Created
May 14, 2012 18:09
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>'; | |
} | |
?> |
Hey there @reneegade
Responded to you on the ACF forum, and I apologize for the slow response time -- travel and e-mail filters are my downfall!
Let me know if you're still working through this.
Phillip.
Hi Phillip,
Thanks for getting back to me - I found a work around ... not sure how
elegant it is but it works!
Cheers
Renee
…On 13/06/2012, at 12:19 PM, Phillip Smith wrote:
Hey there @reneegade
Responded to you on the ACF forum, and I apologize for the slow
response time -- travel and e-mail filters are my downfall!
Let me know if you're still working through this.
Phillip.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2695431
---
E [email protected]
W adnova.com.au
T (02) 4360 1716
M 0405 09 0097
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 Phillip,
Also posted this at ACF ...
Great example, very clear and works a treat - thanks for this. I'm trying to extend this further and want the link to echoed to go to a pdf attachment associated with the custom post type. How would I go about calling a field called 'publication_attachment' instead of the guid?
I have been trying all combinations with the following line but can't seem to work it out.
<code>echo '<a href="' . $related->guid . '">' . $related->post_title . '</a>';</code>
Any help most appreciated. Ta. Renee