Home › Forums › Add-ons › Repeater Field › Query repeater field with two values › Reply To: Query repeater field with two values
I have this code example for a project if it helps (it’s not WP_Query but get_posts, seance is my custom post type, seances a repeater field and film is a relationship field) :
<?php
$today = date("Ymd");
$date = strtotime($today);
$seances = get_posts(array(
'suppress_filters' => FALSE,
'post_type' => 'seance',
'meta_key' => 'date',
'orderby' => 'meta_value_num',
'order'=>'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'seances_%_film', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
),
array(
'key' => 'date',
'compare' => '>=',
'value' => $today,
)
)
));
?>
And in functions.php
function my_posts_where( $where ) {
global $wpdb;
$where = str_replace(
"meta_key = 'seances_",
"meta_key LIKE 'seances_",
$wpdb->remove_placeholder_escape($where)
);
return $where;
}
add_filter('posts_where', 'my_posts_where');
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.