Okay
  Public Ticket #3695230
Search result chronological order
Closed

Comments

  •  28
    Co-Brains started the conversation

    Hi!

    i'm using your theme on my website and the search searches by posts and pages. i would like the results to be shown in chronological order so that i see the most recent articles last. how can i do this?

    Thank you

    have a nice day

  •  8,859
    Tahir replied

    Hey Again,

    Try adding this code snippet via Child Theme functions.php or via a plugin and check: 

    function custom_search_order( $query ) {
        if ( $query->is_search && !is_admin() ) {
            $query->set( 'orderby', 'date' );
            $query->set( 'order', 'DESC' );
        }
        return $query;
    }
    add_filter( 'pre_get_posts', 'custom_search_order' );
    

    Thanks.


    ThemeNectar Support Team