Home › Forums › General Issues › Reverse Relationship Meta Query › Reply To: Reverse Relationship Meta Query
The code is part of the bank CPT single-post template. I’ve tried many iterations, but here’s where it currently stands:
<?php
/*
* Template Name: Bank Review Test
* Template Post Type: banking
*/
add_action ( 'genesis_before_entry_content', 'banking_data');
function banking_data(){
$post_id = get_the_ID();
$accounts = get_posts(array(
'post_type' => array('bank_accounts','money_market_account','checking_accounts'),
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'bank_relationship', // name of custom field
'value' => $post_id, // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE',
)
)
));
if( $accounts ):
?>
<ul>
<?php foreach( $accounts as $account ): ?>
<li>
<?php echo get_the_title( $account->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif;
}
genesis();
?>
Note that the 3 post types all use the same ACF relationship field that points to the bank CPT. I’ve also tried hard-coding the post ID with no success.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.