Support

Account

Home Forums Add-ons Repeater Field Query posts with ACF values from a subfield Reply To: Query posts with ACF values from a subfield

  • An update, I’m trying to use an example from here 4. Sub custom field values
    I’ve updated REPEATER name to ‘quote’

    <?php
    
        // filter
        function my_posts_where( $where ) {
    
        	$where = str_replace("meta_key = 'quote_$", "meta_key LIKE 'quote_%", $where);
    
        	return $where;
        }
    
        add_filter('posts_where', 'my_posts_where');
    
        // vars
        $person = '"' . get_the_ID() . '"';
    
        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
        // args
        $args = array(
        	'posts_per_page' => 10,
            'paged' => $paged,
            'order' => 'DESC',
        	'post_type' => 'recipes',
        	'meta_query' => array(
            	array(
            		'key' => 'quote_$_person',
            		'value' => '"' . get_the_ID() . '"',
            		'compare' => 'LIKE',
            	)
            )
        );
    
        $the_query = new WP_Query( $args );
        if($the_query->have_posts() ) :
            while ( $the_query->have_posts() ) :
               $the_query->the_post();
    
               get_template_part( 'template-parts/content-recipe-card', get_post_format() );
    
            endwhile;
    
        else: ;
        endif;
    
        ?>