Support

Account

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; ?>