Support

Account

Home Forums General Issues Quering relationship field on other post type?

Helping

Quering relationship field on other post type?

  • Hi,

    https://www.advancedcustomfields.com/resources/querying-relationship-fields/

    I followed this tutorial, for quering relationship fields from one post type on an other custom post type. It works great.

    But in one case the relationship field is a subfield of a repeater field. And there it does not work. I am trying since days but don’t get it working. Is this “two direction quering” not possible for relationship fields which are subfields of a repeater field?

    This is the code which works with normal relationship fields but not for the one inside the repeater:

    
    <div class="entry-content">
    						
    <?php 
    	$authors = get_posts(array(
    		'post_type' => 'page',
    		'meta_query' => array(
    			array(
    			'key' => 'author-name', 
    			'value' => '"' . get_the_ID() . '"', 
    			'compare' => 'LIKE'		
    			)
    		)
    	));
    
    ?>
    
    <?php if( $authors ): ?>
    <ul>
    	<?php foreach( $authors as $authors ): ?>
    								
    	<li>
    	<a href="<?php echo get_permalink( $authors->ID ); ?>">
            
            <div class="book-cover">
    	<?php echo get_the_post_thumbnail ( $authors->ID, 'full');  ?>
            </div>
    		
    	<?php echo get_the_title( $authors->ID ); ?>
    	</a>
    	</li>
    	
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    
    </div>
    
    
  • Did you get this to work? I had a similar problem that stumped me for days. Instead of:

    'value' => '"' . get_the_ID() . '"',

    this worked:

    'value' => get_the_ID(),

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

The topic ‘Quering relationship field on other post type?’ is closed to new replies.