Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Try this matthewaprice.com/search-multiple-custom-fields-in-wordpress –  user10874 Dec 5 '11 at 19:09
add comment

1 Answer 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 );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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