Order posts by custom date field

[ad_1]

I would like the serach results to be ordered by a custom date field (auction_date_new). I use this same field to order the posts on archive pages. BUt it’s not working for the search page.

I have tried the filter:

add_filter( 'relevanssi_modify_wp_query', 'rlv_desc_date' );
function rlv_desc_date( $query ) {
	$query->set( 'meta_key', 'auction_date_new' );
    $query->set( 'order', 'DESC' );
	$query->set( 'orderby', 'meta_value_date' );
    return $query;
}

and variations of it. It changes the order, but seemingly randomly. It’s not in order of date (newest to oldest).

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer