0

I have a post type and I want to sort posts in its archive according to two values:

  1. by a meta value called "artwork_year" which contains a 4 digit number (year)
  2. by post publish date

what the query should do is: first get the artwork_year and sort the posts accordingly (show first higher number... ie first 2012 artwork, then 2011, then 2010, etc), then since many posts share the same year, sort them by publish date.

I followed instructions at http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters then tried with

    $artwork = array(

           'post_type' => 'artwork',   
           'posts_per_page' => 10,
           'paged' => get_query_var( 'paged' ),
           'meta_key' => 'artwork_year', 
           'orderby' => 'meta_value_num date', 
           'order' => 'DESC'

    );

    query_posts( $artwork ); 

    while ( have_posts() ) : the_post(); 

           // loop stuff

    endwhile;

    wp_pagenavi();

however, if I do this... the order is not right... now I set it to DESC which is the default; it should display first artwork from 2012, then 2011... and sort the artwork with the meta value 2011 or 2012 according to pub date... however what I get is first 2011 artwork in any case (regardless of if order is set to ASC or DESC) then 2012 posts... how do I get 2012 first and then 2011 and all others?

thank you!

2 Answers 2

1

You have syntax error in query arguments: 'orderyby'.

1
  • oh damn, I changed that after I noticed it was set to order_by, then did another typo... thank you so much - anyway the sorting is still not perfect: the order sort is displaying posts with '2011' first, while it should display '2012' first. Do you have any clue why the sorting is like that?
    – unfulvio
    Jun 29, 2012 at 12:00
1

If you take a look at the line below, you will find that there is an extra "y" in the 'orderby' parameter. Removing that should fix it.

 'orderyby' => 'meta_value_num date', // note: I also tried with meta_value
3
  • thanks, see my reply to Max - however there's still one issue with the sort order
    – unfulvio
    Jun 29, 2012 at 12:00
  • Have you tried to place the value "date" before "meta_value_num"? so that it would be "date meta_value_num" instead.
    – Andre A
    Jun 29, 2012 at 12:07
  • no it doesn't work: posts sorting is inaccurate (shows posts from 2011 and 2012 all mixed) and again if I change DESC or ASC it has no effect... The reason I need this is that the artist I'm creating the website for is uploadinng his artwork throught the years randomly, and pubdate does not reflect the artwork creation order
    – unfulvio
    Jun 29, 2012 at 12:11

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.