[Resolved] Custom sort on category archive

Home Forums Support [Resolved] Custom sort on category archive

Home Forums Support Custom sort on category archive

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #784072
    Joe

    Hello-

    I was wondering what the best way would be to display the archive page of a specific category by title, but leave all the others in the default date order. I have tried modifying the functions.php in my child theme, but can not seem to find the correct filter snippet. Thanks!

    #784106
    Joe

    If someone could help me with this, it would be great. Thank you!

    #784140
    Joe

    Tom, could you help with this?

    #784152
    Leo
    Staff
    Customer Support

    Hi there,

    GP itself doesn’t control how the archive pages are displayed – they are all generated by WordPress itself.

    I did a quick Google search and perhaps this would help?
    https://wordpress.stackexchange.com/questions/39817/sort-results-by-name-asc-order-on-archive-php
    https://codex.wordpress.org/Alphabetizing_Posts

    The term I searched was “wordpress sort archive alphabetically” and there are lots of suggestions/solutions.

    Hope this helps!

    #784154
    Joe

    Hello-

    Thank you!

    I actually got this to work:

    add_action( ‘pre_get_posts’, ‘my_change_sort_order’);
    function my_change_sort_order($query){
    if(is_archive()):
    //If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
    //Set the order ASC or DESC
    $query->set( ‘order’, ‘ASC’ );
    //Set the orderby
    $query->set( ‘orderby’, ‘title’ );
    endif;
    };

    But can you tell me how to apply it to just one category?

    #784168
    Joe

    Hmmm – think I fixed it. Thanks!

    #784171
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.