Home › Forums › General Issues › Query ACF field with nested AND OR LIKE
Hello,
I am desperately trying to make the following query work:
$args = array (
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => array( 'my-cpt' ),
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'place_clause_1' => array(
'key' => 'place',
'value' => '"14979"',
'compare' => 'LIKE',
),
'place_clause_2' => array(
'key' => 'place',
'value' => '"8917"',
'compare' => 'LIKE',
),
),
),
'date_clause' => array(
'key' => 'date',
'value' => date('YmD'),
'compare' => '>=',
),
'heure_clause' => array(
'key' => 'time_start',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'date_clause' => 'ASC', 'heure_clause' => 'ASC'
)
);
$cal_query = new WP_Query( $args );
It returns nothing, whereas the following query returns 1 result (which is what I would expect from the previous query as well…)
$args = array (
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => array( 'my-cpt' ),
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'place_clause_1' => array(
'key' => 'place',
'value' => '"14979"',
'compare' => 'LIKE',
),
//'place_clause_2' => array(
// 'key' => 'place',
// 'value' => '"8917"',
// 'compare' => 'LIKE',
// ),
),
),
'date_clause' => array(
'key' => 'date',
'value' => date('YmD'),
'compare' => '>=',
),
'heure_clause' => array(
'key' => 'time_start',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'date_clause' => 'ASC', 'heure_clause' => 'ASC'
)
);
$cal_query = new WP_Query( $args );
I use ACF Pro 6.2.7 with WP 6.4.3 if it matters.
I can mention as well that in my example above the only ‘place’ field satisfying both the ‘date_clause’ and the ‘heure_clause’ contains a:1:{i:0;s:5:"19479";}
.
Eventually! Bad nesting syntax of mine, not related to ACF, sorry.
$args = array (
'posts_per_page' => -1,
'post_status' => 'publish',
'post_type' => array( 'my-cpt' ),
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'place',
'value' => '"14979"',
'compare' => 'LIKE',
),
array(
'key' => 'place',
'value' => '"8917"',
'compare' => 'LIKE',
),
),
'date_clause' => array(
'key' => 'date',
'value' => date('YmD'),
'compare' => '>=',
),
'heure_clause' => array(
'key' => 'time_start',
'type' => 'NUMERIC',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'date_clause' => 'ASC', 'heure_clause' => 'ASC'
)
);
$cal_query = new WP_Query( $args );
You must be logged in to reply to this topic.
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.