DescriptionDescription
This filter is called before the grid query is ran to fetch posts, terms or users.
It allows to dynamically change the query args of WP_Query
, WP_Term_Query
or WP_User_Query
.
This filter is only called for grids built with the plugin and will not work with custom and archive queries. In these cases, you need to use pre_get_posts
action of WordPress to modify a query.
ArgumentsArguments
Argument | Type | Description |
$query_args | array | Holds query arguments |
$grid_id | integer | Grid id |
ExampleExample
PHP
functions.php
function prefix_query_args( $query_args, $grid_id ) {
// If it matches grid id 1, we exclude post IDs 1,2,3,4.
if ( 1 === $grid_id ) {
$query_args['post__not_in'] = [ 1, 2, 3, 4 ];
}
return $query_args;
}
add_filter( 'wp_grid_builder/grid/query_args', 'prefix_query_args', 10, 2 );