how can i use multiple meta_key and meta_value in query_posts?

For example, I want to find multiple content with two different meta_key and meta_value. How do I do this?

i using this code but not effective:


please help me...


This is not currently possible with query arguments alone (realm of filtering raw SQL query and such).

If your task is not time-critical then I suggest to wait for upcoming WP 3.1 release. It will feature much more flexible querying capabilities for custom fields.

See Advanced Metadata Queries for post on upcoming improvements.

| improve this answer | |
  $args = array(
        'post_type'         =>  'custompost_type',
        'posts_per_page'    =>  '1',
        'meta_query'        =>  array(
                'relations' =>  'AND', // you can use OR also as your requirement
                    'key'   =>  'serial-number',
                    'value' =>  '123'
                    'key'   =>  'model-number',
                    'value' =>  '456'
        'post_status'       =>  'publish',
    $posts = get_posts($args);

if(sizeof($posts) > 0){
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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