0

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!

1
  • 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. Jan 12, 2013 at 12:07

1 Answer 1

0

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

1
  • But your code just searches within that taxonomy/term and it doesn't sort by it.
    – user23654
    Jan 12, 2013 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.