How to display search results in alphabetical order?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support How to display search results in alphabetical order?

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #47548
    dot832
    dot832
    Participant

    Hi,

    I am searching a custom post type named seed_companies and would like to display the results in alphabetical order (ASC). I tried adding this code to my functions.php but it didn’t work.

    function custom_order_search_results($query) {
        if (!is_admin() && $query->is_main_query() && $query->is_search() && $query->get('post_type') === 'seed_companies') {
    
            $query->set('order', 'ASC');
            
            $query->set('orderby', 'title');
        }
    }
    
    add_action('pre_get_posts', 'custom_order_search_results');
    

    Is there a better way to do this?

    Thank you!

    #47560
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Sure! You can do that via this option: https://i.imgur.com/ye7BMJM.png

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.