I am trying to create a custom query for a loop. I have a CPT Sales and two of the fields are promotion_start and promotion_end, which are ACF Date Picker fields. I have a page that lists sales based on if the current date is <= promotion_start and >= promotion_end. A few questions, if anyone knows:
-I understand I will need to use a custom query filter and it requires the query ID. On the block inspector I see a query class but not a query ID. When I look at the query editor I see it says Query ID 18. Is that the query ID I use, such that the query ID in the filter would be:
$id === 'query-18'
-This is the query filter Iām trying. Since I have two Meta Queries, I added two values. I assume that is needed.
<?php
add_filter( 'cwicly/query/args', function( $query_args, $attributes, $id ) {
if ($id === 'query-18') {
$query_args['meta_query'][0]['value'] = date('Y-m-d');
$query_args['meta_query'][1]['value'] = date('Y-m-d');
}
return $query_args;
}, 10, 3 );
?>
-These are my Meta Queries - The start screen:
The first Meta Query:
The second Meta Query:
-Instead of filtering the items, all are returned. I looked at the code and see that the Keys in the Meta Queries are Null.
<?php
// The Arguments
$args = array (
'post_type' =>
array (
0 => 'on-sale',
),
'ignore_sticky_posts' => true,
'meta_query' =>
array (
'relation' => 'AND',
0 =>
array (
'key' => NULL,
'compare' => '<=',
'type' => 'DATE',
'value' =>
array (
),
),
1 =>
array (
'key' => NULL,
'compare' => '>=',
'type' => 'DATE',
'value' =>
array (
),
),
),
'orderby' => 'title',
'order' => 'ASC',
);
// The Query
$the_query = new WP_Query( $args );
Iāve pieced this approach together by looking at other posts in the forum here, so I probably misunderstood or missed a step. Any help is appreciated.