mag
asked 3 months ago

Hello DesignWall team, I have a paid version of DW Focus and I was wondering if you can help me making the search result page sorted by date in descending order.
Thank you for your reply

1 Answers
DominicStaff
answered 3 months ago

You can add the following code to the functions.php file:

add_filter('posts_orderby','my_sort_custom',10,2);
function my_sort_custom( $orderby, $query ){
    global $wpdb;
    if(!is_admin() && is_search())
        $orderby =  $wpdb->prefix."posts.post_type DESC, {$wpdb->prefix}posts.post_date ASC"; 
    return  $orderby;
}
Powered by DW Question & Answer Pro