Skip to content

Instantly share code, notes, and snippets.

@ashfame
Created March 19, 2014 20:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashfame/9650343 to your computer and use it in GitHub Desktop.
Save ashfame/9650343 to your computer and use it in GitHub Desktop.
Querying post relationships in reverse direction when using Advanced Custom Fields plugin on WordPress
<?php
$tour_pages = get_posts(
array(
'post_type' => 'tour',
'meta_query' => array(
array(
'key' => 'tour_author_relationship', // name of custom field
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
)
);
if ( ! empty( $tour_pages ) ) {
echo '<a href="' . get_permalink( $tour_pages[0]->ID ) . '">Author on Tour</a>';
}
?>
@mrpaulphan
Copy link

This is exactly what I needed. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment