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 have a custom post type with a custom taxonomy and I am trying to pull posts with a certain meta value along with a custom taxonomy (tag in my case). Is this possible and if so, how would the query looK?

Here is a excerpt of how I am pulling the posts with just meta value and it works fine.

$args = array(
'post_type' => 'box',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'meta_value_num',
'meta_key' => 'position',
'taxonomy' => 'box-cat'
);

$boxes = new WP_Query( $args );

So this successfully pulls all the posts that are in "box-cat" category and ordered by the "position" value. But I have also a tags taxonomy that I would like to add into the query as orderby....How can this be done?

Thanks!

share|improve this question
    
There's no way to currently do an order by with taxonomies. Taxonomies are meant to group posts, anyway, so the WP developers haven't added that functionality in. –  Manny Fleurmond Jan 12 '13 at 12:07

1 Answer 1

I have the similar query in my blog. This my args array :

$args= array(
    'post_type' => 'box',
    'posts_per_page' => -1,
    'meta_key' => 'position',
    'order' => 'DESC',
    'orderby' => 'meta_value_num',
    'tax_query' => 
        array(
            array(
                'taxonomy' => 'taxonomyname',
                'field' => 'slug',
                'terms' => 'yourterm'
            )
        )
);

Hope it will help you

share|improve this answer
    
But your code just searches within that taxonomy/term and it doesn't sort by it. –  Rick Jan 12 '13 at 15:43

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.