Frustrated and would love some help with this.
I have a custom post field titled 'expire_date'. When the expire date is reached, I want that post to to drop off of the list of posts that are returned.
I use Generate Blocks, and support at Generate Press were kind enough to give me some code that they say should work for what I want.
However, it doesn't. None of the posts I want filtered out are filtered out.
I've tested the 'if' statement and that query_args do work by using a different query_arg. It worked fine (and is included in the script below).
But the actual script that I need to work doesn't. I've tested every way that I can think of, double checked the custom field and it's working and titled correctly. I've changed the comparison operator to = and even tried != and it doesn't make any difference. Nothing is filtered out. Why?
Thanks for any help!
Chris
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
if (
! is_admin()
&& ! empty( $attributes['className'] )
&& strpos( $attributes['className'], 'my-query' ) !== false
) {
// pass meta_query parameter
$query_args[ 'meta_query' ] = array(
'meta_key' => 'expire_date', //example 2022-06-20
'meta_value' => date("Y-m-d"),
'type' => 'DATE', //have also tried DATETIME and TIME
'meta_compare' => '>=',
);
////in testing, this works/// $query_args['date_query'] = array( 'after' => '2022-06-01' );
}
return $query_args;
}, 10, 2 );
>=
higher or equal to/ present and future ).meta_query
is normally meant to indicate what you want, not what you don't want. I do see though that this is a generateblocks question, you need to go back to their support route, or ask other generatepress/generateblock users in their communities. 3rd party plugin/theme dev support questions are offtopic heretype
also bemeta_type
?pre_get_posts
filter, but it is not, and you have no guarantee that it would work if we did. That's ignoring$attributes
. Eitherway it's sophistry