Elementor: Search Result Custom Order

To add this code, go to Dashboard > Appearance > Theme File Editor and add one of these codes at the bottom of function.php.

This one to show the latest posts first.

				
					remove_filter( 'posts_search_orderby');
add_filter( 'posts_search_orderby');
function rl_posts_search_orderby( $orderby, $query ) {
	if ( isset( $query->query['s'] ) ) {
		$orderby = 'post_date DESC';
	}
	return $orderby;
}

				
			
				
					add_filter( 'pre_get_posts', 'enfold_customization_random_search' );
function enfold_customization_random_search( $q ) { 
	if ( $q->is_search ) { $q->set( 'orderby', 'rand' ); }
	return $q;
}