/facet/query_string

Description Description

This filter is called before the content is queried from WP_Query, WP_Term_Query or WP_User_Query.

It allows to filter content by adding facet slug/values in the query string. This filter is pretty useful to prefilter content on load.

ArgumentsArguments

ArgumentTypeDescription
$query_string arrayHolds query strings parameters
$grid_id mixedGrid ID or template ID/name
$action stringCurrent action type (render or refresh)

ExampleExample

PHP
functions.php
function prefix_filter_query( $query_string, $grid_id, $action ) {

	// If the content is not filtered on first render.
	if ( 'render' === $action && empty( $query_string ) ) {
		
		$query_string = [
			'rating_facet_slug'   => [ '4' ],
			'price_facet_slug'    => [ '35', '150' ],
			'category_facet_slug' => [ 'clothing', 'hoodies' ]
		];
	}
	
	return $query_string;
	
}
add_filter( 'wp_grid_builder/facet/query_string', 'prefix_filter_query', 10, 3 );