I have a custom post type called promotions.
In each promotions' post meta, I store two fields, promo_start_date and promo_end_date.
The idea is to only show promotions on the frontend, where the
current_date >= promo_start_date AND current_date <= promo_end_date
For example, if the promotion has the value of 2022-12-18 in the promo_start_date and 2023-01-08 in the promo_end_date, it will only show up on the frontend on the 2022-12-18 and then display till the 2023-01-08.
I was wondering how possible it is to achieve this with meta_query.
$args = [
'paged' => 1
'post_type' => 'promotions',
'posts_per_page' => 15,
'meta_query' => [
[
'key' => 'promo_start_date'
'value' => 'CURRENT_DATE'
'type' => 'DATE'
'compare' => '>='
],
[
'key' => 'promo_end_date'
'value' => 'CURRENT_DATE'
'type' => 'DATE'
'compare' => '<='
],
],
];
I can easily implement this in raw sql but unfortunately I am tweaking a filter for a plugin in order to achieve the result that I need.
The filter is coming from the Search and Filter plugin and its documentation can be found here
And here is an example of the code that I am trying to implement
function me_sf_edit_query_args($query_args, $sfid) {
// if search form has specified ID, change query args
if ($sfid == 11000) {
$query_args['meta_query'] = [
[
]
];
dd($query_args);
}
return $query_args;
}
add_filter('sf_edit_query_args', 'me_sf_edit_query_args', 20, 2);
Thank you
'relation' => 'and'property? or are you having issues with the values? You can check it here developer.wordpress.org/reference/classes/wp_query/…Y-m-d H:i:sY-m-d, because that information is coming fromAPImeta_querymight be able to do what you want, there is no guarantee that this is still true when the plugin is involved, and the plugin may have special requirements that need to be handled that require specialised knowledge of the plugin. As a result any answer you get here may be correct but unusable