Skip to content

Instantly share code, notes, and snippets.

@ashfame ashfame/snippet.php
Created Mar 19, 2014

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Mar 10, 2017

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
You can’t perform that action at this time.