0

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: ____
Size:
____
Price: ___
Condition:
___
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

1 Answer 1

1

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

$args = array(
    'post_type' => 'product',
    'meta_query' => array(
        array(
            'key' => 'color',
            'value' => 'blue',
            'compare' => 'NOT LIKE'
        ),
        array(
            '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.