Search Result Custom Order

11 months ago

< 1 min read

Posted by:

Focus

Subscribe to newsletter

By subscribing you agree to with our Privacy Policy.

Share

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

BY DATE DESC

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;
}

RANDOM ORDER

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;
}

Read more

See How It Works

Create better websites, faster.

Download the Entire Library

Adaptative, neutrally designed components.

Customer Service

Focus Website

Today, September 8

Hi, there 👋

How can I help you?

Start Chat with:

We use cookie to improve your experience on our site. By using our site you consent cookies.