Home › Forums › General Issues › Reverse Relationship Query › Reply To: Reverse Relationship Query
OK. I got this working. Here is my code for reference.
<?php
$tasks = get_posts(array(
'post_type' => 'task',
'meta_query' => array(
array(
'key' => 'task_parents', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $tasks ): ?>
<table>
<?php foreach( $tasks as $tasks ):?>
<tr>
<td>
<a href="<?php echo get_permalink( $tasks->ID ); ?>">
<?php echo get_the_title( $tasks->ID ); ?>
</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
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!
🚀 ACF & ACF PRO 6.0.7 are now available.
— Advanced Custom Fields (@wp_acf) January 18, 2023
✨This release contains bug fixes and improvements while we continue to work on the next major release of ACF.https://t.co/wQgAOpwmUI
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.