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 can't seem to figure this out.

The following query works:

$xxxx = new WP_Query(array(
'listset' => 'homepage',
'meta_query' => array(
    array (
        'key' => 'show_home',
        'value' => 'true',
        'compare' => '='
    )
),
'posts_per_page' => 1,
'post_type' => 'lists',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
));

The following does not:

$xxxx = new WP_Query(array(
'tax_query' => array(
    array (
        'taxonomy' => 'listset',
        'field' => 'slug',
        'terms' => 'homepage'
    )
),
'meta_query' => array(
    array (
        'key' => 'show_home',
        'value' => 'true',
        'compare' => '='
    )
),
'posts_per_page' => 1,
'post_type' => 'lists',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC'
));

Anyone can help me figure out why the second one doesn't work?

share|improve this question
add comment

2 Answers 2

The terms for the tax_query should be an array.

share|improve this answer
    
Still doesn't fix it and according to the help doc, it doesn't need to be: codex.wordpress.org/Class_Reference/WP_Query –  Koitan Mar 27 '12 at 20:08
    
Ah, and I definitely meant to leave this as a comment, not an answer. Oh well :) –  helenhousandi Mar 27 '12 at 21:41
    
Should I convert it to a comment? –  toscho Mar 28 '12 at 12:28
    
@toscho: If you'd like. It sort of stands as an answer (in my experience, I've needed to use an array and not just a string, even for a single term), but then I should probably flesh it out more. –  helenhousandi Mar 28 '12 at 16:32
    
Your decision. I’d rather see a good answer. :) –  toscho Mar 28 '12 at 17:14
add comment

You say that "the second one doesn't work", but it's not clear in what way it doesn't work, and in what way you expect it to work. The query you've put together will only match posts that BOTH have listset = 'homepage' AND show_home = 'true'. Are you sure that there are posts in your database where this is true? Is this what you mean to be querying?

I don't think that it's possible to do an OR between meta_query and tax_query using WP_Query alone. You would probably have to either do two queries (the first would give the post__in parameter for the second) or filter posts_where and do some fancy regex.

share|improve this answer
    
I mean it doesn't work in that query1 returns results while query2 returns nothing. And yes, that is the query I want. listset = homepage (taxonomy) and show_home = true (meta field data). –  Koitan Mar 27 '12 at 20:18
1  
You mean it literally returns nothing? Or it returns a WP_Query object with empty results? –  Boone Gorges Mar 27 '12 at 20:53
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.