-
cssweb
Aloha and Happy New Year!!
For my Post Category archive pages, I created a Block Element (with a Query Loop).
Location: All Archives
‘Inherit query from template’ is ON
It works beautifully, but I need the results to display by Title/alphabetically.
They’re being displayed by Publish Date/Time .. which makes sense when I think about it 🙂
Have I taken the wrong approach on this?
Do I need to change directions to control order?
Many thanks, as always, to the entire GP Team 🙂
– Bill/Hawaii
-
Alvind
Hey Bill, happy new year too!
Try adding this snippet:
function sort_posts_alphabetically($query) { if (!is_admin() && $query->is_main_query()) { if ($query->is_category()) { $query->set('orderby', 'title'); $query->set('order', 'ASC'); } } return $query; } add_action('pre_get_posts', 'sort_posts_alphabetically');
Adding PHP: https://docs.generatepress.com/article/adding-php/
-
cssweb
I knew it was gonna be a snippet!!
It worked perfectly – thanks a million, Alvind.
You’re a wizard!!
Bill
-
Alvind
You’re welcome, glad to be of help!
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.