[Support request] How to Reverse the Post Order of a Specific Category?

Home Forums Support [Support request] How to Reverse the Post Order of a Specific Category?

Home Forums Support How to Reverse the Post Order of a Specific Category?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #760860
    Jungsu

    Hello.
    How can I reverse the post order of a specific category. I hate to use the plugin. Thanks,

    #761064
    David
    Staff
    Customer Support

    Hi there,

    try this function:

    function change_category_order( $query ) {
        if ( $query->is_category('8') && $query->is_main_query() ) {
            $query->set( 'order', 'ASC' );
        }
    }
    add_action( 'pre_get_posts', 'change_category_order' );

    https://docs.generatepress.com/article/adding-php/

    Just change the category ID to match your selection.

    #761068
    Jungsu

    The issue is resolved. Thank you!!

    #761069
    David
    Staff
    Customer Support

    You’re welcome

    #1814470
    marc

    Hi,

    If I may hijack this thread:

    how would you apply this to all categories?

    I tried something like this but it doesn’t work:

    function change_category_order( $query ) {
    if ( $query->is_category(‘8’, ‘9’, ’10’) && $query->is_main_query() ) {
    $query->set( ‘order’, ‘ASC’ );
    }
    }
    add_action( ‘pre_get_posts’, ‘change_category_order’ );

    Thanks in advance,

    #1814592
    David
    Staff
    Customer Support

    Hi there,

    try this:

    function change_category_order( $query ) {
        if ( $query->is_category() && $query->is_main_query() ) {
            $query->set( 'order', 'ASC' );
        }
    }
    add_action( 'pre_get_posts', 'change_category_order' );
    #1814645
    marc

    Thanks David it worked.

    Is there a way to make a specific post within a specific category featured?

    I can only see the “make first post featured” option.

    Thanks,
    Marc

    #1814729
    David
    Staff
    Customer Support

    Theres a plugin that allows you to set a Sticky Post for specific categories:

    https://wordpress.org/plugins/category-sticky-post/

    Its the only way that i know that is possible, but the plugin is out of date, but some users looking at the reviews are still using it….

    #1814780
    marc

    Ok thanks for that.

    #1814784
    David
    Staff
    Customer Support

    You’re welcome

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