-
Hi,
I created a CPT with a date field called datum (date).
Only future events should be displayed.I gave the grid in the query the class show-future-courses.
The following code was added:
add_filter( ‘generateblocks_query_loop_args’, function( $query_args, $attributes ) {
if ( ! is_admin() && ! empty( $attributes[‘className’] ) && strpos( $attributes[‘className’], ‘show-future-courses’ ) !== false ) {
// Get the current date
$current_date = date(‘Y-m-d’);// Modify query arguments
$query_args = array_merge( $query_args, array(
‘meta_key’ => ‘datum’,
‘meta_type’ => ‘DATE’,
‘orderby’ => ‘meta_value’,
‘order’ => ‘ASC’,
‘meta_query’ => array(
array(
‘key’ => ‘datum’,
‘value’ => $current_date,
‘compare’ => ‘>’,
‘type’ => ‘DATE’
),
),
));
}
return $query_args;
}, 10, 2 );But it does not work.All events are showing.
https://postimg.cc/gallery/8v8S2KS
What am I doing wrong?
Best regards, Sandra
-
Hi Sandra,
You are using the v2 query block; try moving the class from the Grid block to the query block (the Grid is not native to the v2 query block).
And change the filter name from
generateblocks_query_loop_args(v1) togenerateblocks_query_wp_query_args(v2).Let me know if this helps!
-
Yes, that helps. Thanks!
-
Glad to hear that 🙂
- You must be logged in to reply to this topic.