Support

Account

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

Solved

Query posts with ACF values from a subfield

  • Hi, is there a way to query posts if values of relationship inside a repeater matching with the page id?

    On CPT ‘recipes’ – repeater is listing people recommending the recipe, I’m unable to use the RELATIONSHIP outside REPEATER field as I need to include a comment from this person. So the structure looks like this REPEATER=’people_recommended_quotes’ with RELATIONSHIP=’person’ and TEXT=’comment’

    Would that be the right logic for listing recipes that person recommended alongside related comment?

    Thanks!

  • 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;
    
        ?>
    
  • Update this was sorted with 4. Sub custom field values

    I’ve changed the REPEATER name to ‘quote’

    
    // 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() . '"';
        $personID = 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',
            	)
            )
        );
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.