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 make a custom search box and let user do search. I have added required field to my editing panel by custom meta box. I have a post which have some meta data like London as place and 13021 as post code. I want result when kawsar_pa_place = london and kawsar_pa_pc = 13021. For that cause, i use 'relation' => 'AND'. But i got 0 result found.

I made query by following argument:

$args = array(
  'cat'=> '3',
  'posts_per_page' => '4',
  'orderby' => 'rand',
  'paged' => $paged,
  'meta_query' => array(
      'relation' => 'AND',
      array(
        'key' => 'kawsar_pa_place',
        'value' => 'dhaka'
      ), 
      array(
        'key' => 'kawsar_pa_pc',
        'value' => '1362',
        'type' => 'numeric',
        'compare' => '='
      )
   )
);

If i set 'relation' => 'OR', it is working fine. But i want result if all are matched.

I also tested with BETWEEN, it also work fine.

Please help me. Thanks.

share|improve this question
    
What you posted suggests that there are no posts that match, in which case 0 results is correct. Why do you think that meta_query is broken? –  s_ha_dum Jun 2 '13 at 20:33
    
I have a post which have some meta data like London as place and 13021 as post code. I want result when kawsar_pa_place = london and kawsar_pa_pc = 13021. For that cause, i use 'relation' => 'AND'. But i got 0 result found. Thanks –  itskawsar Jun 2 '13 at 20:40
1  
Post the output of var_dump($yourquery->request); –  s_ha_dum Jun 2 '13 at 20:43
    
diigo.com/item/note/2iygi/35eg please let me know, if you are not able to see. thanks –  itskawsar Jun 2 '13 at 23:05
    
The SQL is correct. Something else is wrong-- post_type, post_status, something. Or you don't have the data in the database the way you think you do. –  s_ha_dum Jun 2 '13 at 23:11

1 Answer 1

up vote 0 down vote accepted

What you posted suggests that there are no posts that match, in which case 0 results is correct.

I don't think that the meta_query is broken. The SQL looks right to me, which means that you don't have the meta_key/meta_value pairs in the database that you think you do, or that something else about the query is wrong-- post_type, post_status, the cat condition, something.

share|improve this answer

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.