Home Forums ACF PRO Query relationship from repeater sub field from other post


Query relationship from repeater sub field from other post

  • Hi,
    Im looking for solution for Query relationship from repeater sub field in other post…

    That query works fine, if I have a repeater field in other post

    	*  Query posts for a relationship value.
    	$locations = get_posts(array(
    		'post_type' => 'store_post',
    		'meta_query' => array(
    				'key' => 'chef', // name of custom field
    				'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    				'compare' => 'LIKE'
    	<?php if( $locations ): ?>
    		<?php foreach( $locations as $location ): ?>
    			<?php echo get_the_title( $location->ID ); ?>
    <?php endforeach; ?>
    <?php endif; ?>

    …but in other post I have repeater field with subfield, and the sub field is where I want to check if my id (get_the_ID()) is in it. Quick solution anyone?

  • You can’t do a query in WP that queries posts based on fields in other posts.

    You would need to query the field in the other post and then query the posts you want based on the results of that query. Not a quick solution at all.

    So basically:

    1. Query the the possible related posts
    2. Dynamically build a new query
    3. Query the posts

    If you are interested I created a new plugin recently that will pull the data from the related post into the post you want to query so that you can query the those values directly and I’m looking for input on it. I posted the information here:

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.