• Resolved Richard Brown

    (@cregy)


    Hi

    I’m creating a simple dictionary of Biblical terms and I want to be able to sort that category A to Z. I know there are plugins out there but I was also looking to see if I could add it as code in my functions.php file please?

    Thanks

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • luisherranz

    (@luisherranz)

    I believe you should be able to do it with something like this:

    function sort_dictionary_posts_alphabetically($query) {
        if (!is_admin() && $query->is_main_query() && is_category('7-dictionary')) {
              $query->set('orderby', 'title');
              $query->set('order', 'ASC');
        }
    }
    add_action('pre_get_posts', 'sort_dictionary_posts_alphabetically');
    

    Let me know if it works, but I haven’t tested it though, so be careful.

    Thread Starter Richard Brown

    (@cregy)

    Works perfectly. A huge thanks.

    luisherranz

    (@luisherranz)

    Awesome ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category sorting A to Z’ is closed to new replies.