Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

alpha order – loop template – category archive

  • 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

  • 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/

  • I knew it was gonna be a snippet!!

    It worked perfectly – thanks a million, Alvind.

    You’re a wizard!!

    Bill

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