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 been trying to figure out how to do this for a few hours now and Have final given in to asking for help.

I've got 3 custom post types that I need to query for a term called home which is inside a taxonomy on each one.

hope I've been clear with what I want to achieve, here is the code I'm using at the moment.

            <?php
          $args = array(
        'post_type' => array( 'testimonial', 'casestudy', 'post'),
        'posts_per_page' => 1,
        'tax_query' => array (
        'relation' => 'OR',
        array(
        'taxonomy' => 'testimonial_category',
        'terms' => 'home'
        'field' => 'slug'
        ),
        array(
        'taxonomy' => 'casestudy_category',
        'terms' => 'home'
        'field' => 'slug'
        ),
        array(
        'taxonomy' => 'category',
        'terms' => 'home'
        'field' => 'slug'
        ),
        )
);

        $query = new WP_Query( $args );
        $postcount = 0;
            ?>
           <?php if ($query->have_posts()) : ?>
           <?php while ($query->have_posts()) : $query->the_post(); ?>
           <?php $postcount++; ?>
share|improve this question
    
There is a missing comma after each 'terms' => 'home'. Does correcting that fix it? –  s_ha_dum Jun 24 '13 at 14:26
    
I actually managed to fix this now, using the following code 'terms' => array('home'), placing an array around the term slug. the comma was a small typo thanks for pointing it out s_ha_dum. –  dannyw24 Jun 25 '13 at 9:52
add comment

1 Answer

to make this work all I did was add

'terms' => array('home'),

to each term like this above

'terms => 'home'

share|improve this answer
    
I thought "home" was your slug_name. terms should accept an integer, string, or array. –  s_ha_dum Jun 25 '13 at 12:36
    
it depends what you pass in the fields => 'id/slug' –  dannyw24 Jun 25 '13 at 14:12
    
Yes, but you missed the point. Your original code has 'terms => 'home',. your solution is 'terms => array('slug_name'), which is confusing. Are you saying the fix was to use 'terms => array('home'),? –  s_ha_dum Jun 25 '13 at 14:15
    
I've amended my mistake, thanks for pointing this out. –  dannyw24 Jun 25 '13 at 14:28
    
terms => 'home' and terms => array('home') are equivalent as far as this query is concerned. It processes either a string or an array. You may have solved it but this is not that fix. –  s_ha_dum Jun 25 '13 at 14:38
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.