Support

Account

Home Forums Front-end Issues Using meta_query for complex search results

Helping

Using meta_query for complex search results

  • I’m trying to make a custom search form where each post has custom meta data. When I filter by two key values I can get the results. But when I add a third array, amenities, the results don’t appear.

    Is this too complex of a query?

    Here is my query argument:

    	$args_listings = array( 
    		'cat' => 'listings',
    		'meta_query' => array(
    				array(
    					'key'     => 'neighborhood',
    					'value'   => $neighborhoodlist,
    					),
    				array(
    					'key'     => 'bedrooms',
    					'value'   => $bedroomnum,
    					),
    				array(
    					'key'     => 'amenities',
    					'value'   => $amenitieslist,
    					),
    		),
    
    	);

    Eventually I would like to have more filters related to the search.

  • Hi mrdirby,

    have you tried using the ‘relational’ query to set this?

    $meta_query_args = array(
    	'relation' => 'OR', // Optional, defaults to "AND"
    	array(
    		'key'     => '_my_custom_key',
    		'value'   => 'Value I am looking for',
    		'compare' => '='
    	)
    );
    $meta_query = new WP_Meta_Query( $meta_query_args );

    I hope to have helped

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Using meta_query for complex search results’ is closed to new replies.