Support

Account

Forum Replies Created

  • I found this thread https://support.advancedcustomfields.com/forums/topic/reverse-query-relationship-subfield-which-is-nested-in-a-repeater-field/

    Here is the specific code that works for me, just in case seeing a specific helps anyone in the future

    
    <?php 
    // custom filter to replace '=' with 'LIKE'
    function my_posts_where( $where )
    {
    		$where = str_replace("meta_key = 'credits_%_credits__person'", "meta_key LIKE 'credits_%_credits__person'", $where);
     
    		return $where;
    }
     
    add_filter('posts_where', 'my_posts_where');
     
    // args
    $args = array(
    		'post_type' => 'work',
    		'meta_query' => array(
    				array(
    						'key' => 'credits_%_credits__person',
    						'value' => '"' . get_the_ID() . '"',
    						'compare' => 'LIKE'
    				)
    		)
    );
     
    // get results
    $the_query = new WP_Query( $args );
     
    // The Loop
    ?>
    <?php if( $the_query->have_posts() ): ?>
    		<ul>
    		<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    				<li>
    						<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    				</li>
    		<?php endwhile; ?>
    		</ul>
    <?php endif; ?>
     
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
    
  • I made a regular relationship field as a test and the code above for my single-team.php worked, so the challenge is just figuring out how to reverse query the relationship field out of a repeater

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