Created
May 14, 2012 18:09
-
-
Save phillipadsmith/2695431 to your computer and use it in GitHub Desktop.
Example of usign Advanced Custom Fields and querying the reverse relationship. Discussion: http://www.advancedcustomfields.com/support/discussion/1979/how-to-getting-the-reverse-relationship-from-a-relationship-field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $args = array( | |
'numberposts' => -1, | |
'offset' => 0, | |
'orderby' => 'post_date', | |
'order' => 'DESC', | |
'post_type' => 'custom_post_type_here', | |
'post_status' => 'draft', | |
'meta_query' => array( | |
array( | |
'key' => 'custom_field_key_name', | |
'value' => $post->ID, | |
) | |
) | |
); | |
$posts_array = get_posts( $args ); | |
if( $posts_array ) { | |
echo '<ul>'; | |
foreach( $posts_array as $related ) { | |
echo '<li>'; | |
echo '<a href="' . $related->guid . '">' . $related->post_title . '</a>'; | |
echo '</li>'; | |
} | |
echo '</ul>'; | |
} | |
?> |
The 'value' parameter in the meta query doesn't seem to work for me. When removed it brings back all the posts unfiltered.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @reneegade,
Glad to hear it. :)
Phillip.