Site logo

Archived topic

Re-order Posts

1 reply · Started by John on August 7, 2021

Viewing posts 1–2 of 2

Hello GP Support !

I have created a directory. Of posts. They are linked by a category: "Consultants". Please see:

https://understand-culture.com/consultants/

When you choose a consultant from the directory, and then click on the category at the bottom of the post (currently there is only that one), the user gets a stream of posts, aka consultant-profiles.

Great. Excellent. However, the order of the posts is based on when they were created. The most recent post appears at the top. Ok, that's how posts work. However, I'd like the individual posts in the stream ordered alphabetically, based on name.

Is that possible?

Thanks !

John Magee in Bonn, Germany

Hi there,

you can use the pre_get_posts filter to set the orderby for categories that are an ancestor of your consultants category.

add_action( 'pre_get_posts', function($query){
if ( cat_is_ancestor_of(6, get_query_var( 'cat' )) ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC');
   }
});

Change the 6 to match the ID of the Consultants category.

This archived topic is closed to new replies.