I'm just an basic Wordpress user. I need to make search box with multiple criteria inputs (multiple conditions) to search inside various Custom Fields.

For example including following Custom Fields:

Color: ____
Price: ___
Discount %: ___
Hit Count:

User may input 1 or more fileds.
Result should be filtered for multiple input also.
For example: Price: ____100___ and Condition: ____Fair____
So, how can i handle this multiple conditions in Query?

It is ok for every single inputs.
But, problem with more then 1.
I'm confusing how to write query for multiple criteria (in former way).

A simple sample please.


1 Answer 1


have a look at WP_Query(); and use meta_query / tax_query arguments

$args = array(
    'post_type' => 'product',
    'meta_query' => array(
            'key' => 'color',
            'value' => 'blue',
            'compare' => 'NOT LIKE'
            'key' => 'price',
            'value' => array( 20, 100 ),
            'type' => 'numeric',
            'compare' => 'BETWEEN'
$query = new WP_Query( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.