0 days
0 hrs
0 min
0 sec
Prices are going up soon, save upto 60% today

Queries

PHP

Filter query args

add_action( 'search-filter/queries/query/apply_wp_query_args', 'search_filter_docs_update_query_args', 10, 2 );

function search_filter_docs_update_query_args( $query_args, $search_filter_query ) {
	// Get the query ID.
	$query_id = $search_filter_query->get_id();

	// If the query ID is 123, update the order.
	if ( $query_id === 123 ) {
		$query_args[ 'order' ] = 'DESC';
	}

	// Always return the $query_args.
	return $query_args;
}

The query class: Search_Filter\Queries\Query

The query instance class.

Function: get_attributes()

Description: Gets all the attributes for a query (most of the settings you can see in the query editor).
Return: associative array of attributes.
Use: $query->get_attributes()

Function: get_attribute( $attribute_name )

Description: Gets a single attribute by name.
Return: attribute value or null if attribute not found.
Use: $query->get_attribute('singleIntegration')

Function: get_id()

Description: Gets the query ID.
Return: the ID.
Use: $query->get_id()

Find a query

Returns: Search_Filter\Queries\Query or a WP_Error if not found.

By name

$query = \Search_Filter\Queries\Query::find( array(
	'name' => 'My query', // My query
) );

var_dump($query);

By ID

$query = \Search_Filter\Queries\Query::find( array(
	'id' => 123,
) );

var_dump($query);

Find multiple queries

Returns: array of Search_Filter\Queries\Query

Find queries by status

$queries = \Search_Filter\Queries::find( array(
	'status' => 'enabled', // Only get enabled queries.
	'number' => 0, // Get all.
) );

var_dump($queries);

Find queries by integration type

$queries = \Search_Filter\Queries::find( array(
	'status' => 'enabled', // Only get enabled queries.
	'number' => 0, // Get all.
	'meta_query' => array(
		array(
			'key'     => 'integration_type',
			'value'   => 'single',
			'compare' => '=',
		),
	),
) );

var_dump($queries);

JavaScript

Important: we’re still finalising the APIs for this, do not use in production unless you are proactively monitoring our changelogs and ready to update this.

Detect start/stop of fetching results

const queries = window.searchAndFilter.frontend.app.queries.list;
Object.keys(queries).forEach(queryKey => {
	const query = queries[ queryKey ];

	// Don't do anything unless the query ID is 123.
	if ( query.getId() !== 123 ) {
		return;
	}
	
	// Listen for the update to the results.
	query.on('get-results/start', function (queryObject) {
		console.log("Start getting results.");
	});

	// Listen for the update to the results.
	query.on('get-results/finish', function (queryObject) {
		console.log("Finished getting results.");
	});
});