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;
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.