Site logo

Archived topic

How to Reverse the Post Order of a Specific Category?

9 replies · Started by Jungsu on December 18, 2018

Viewing posts 1–10 of 10

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

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.

The issue is resolved. Thank you!!

You're welcome

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,

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' );

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

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....

Ok thanks for that.

You're welcome

This archived topic is closed to new replies.