Extract query and add filtering

Hello, I am trying to add an extra filter on a query used for searching a listing.
I would like to be able to add a restriction on an attribute, regardless of the form.

What I wanted to do was

	function($query,$fields) {
			'pets'   => 'allowed',

but it is not working. What am I doing wrong?
Thanks a lot

If this attribute has checkbox type then please try this PHP snippet. Also, please change hp_pets in the code snippet on the hp_ + your attribute slug or field name

	function($query,$fields) {
		$meta_query = array_filter( (array) $query->get( 'meta_query' ) );
		$meta_query['pets'] = [
			'key' => 'hp_pets',
			'type' => 'CHAR',
			'compare' => 'EXISTS',
		$query->set( 'meta_query', $meta_query );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.