0
votes

Hope someone can help.

I have a custom post type called Collections that needs to be sorted by a custom field called Seasons. On the Collection archive template there is a custom query that sorts posts by season but I can't seem to get the 'order' option to work. On top of that I want the posts within each season to be shown in date added order which they don't at the moment. What I need to achieve is the collections sorted by season (most recent first) and then ordered by date added (most recent first).

The custom query looks like this

<?php 

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args = array(
        'paged' => $paged,
        'posts_per_page' => 4,
        'post_type' => 'collection',
        'meta_key' => 'season',
        'orderby' => 'meta_value meta_value_num'
        'order' => 'DESC'        
        );

    $the_query = new WP_Query( $args );

?>
2

2 Answers

0
votes

I don't know what you have in meta_key 'season' - is it string or number? If it's number I think it should look like this:

<?php 

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    $args = array(
        'paged' => $paged,
        'posts_per_page' => 4,
        'post_type' => 'collection',
        'meta_key' => 'season',
        'orderby' => 'meta_value_num date'
        'order' => 'DESC'        
        );

    $the_query = new WP_Query( $args );

?>
0
votes

make your args as below :

 $args = array(
        'paged' => $paged,
        'posts_per_page' => 4,
        'post_type' => 'collection',        
        'orderby' => 'meta_value_num',
        'meta_key' => 'season',
        'order' => 'DESC'        
        );