• Resolved aosmichenko

    (@aosmichenko)


    Hello everyone,

    I referred to this support thread, but the solution is not working for me.

    Does anybody knows what can cause such result, website running WPML and WP Rocket cache.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Something else may be overriding the search results order. If you look at the WP_Query query variables, are there any orderby parameters set there?

    You need to use the solution in the other thread, because otherwise Relevanssi Light will force the relevance order, but looks like you also need to figure out what else is affecting this. Might be your theme, might be some other plugin.

    Thread Starter aosmichenko

    (@aosmichenko)

    Here is what I found in my query, is that correct?
    ORDER BY relevance DESC, wpim_posts.post_date DESC

    Plugin Author Mikko Saari

    (@msaari)

    No, that is not correct, it sorts by relevance first and date second, and thus doesn’t really get into date sorting.

    It should be ORDER BY wpim_posts.post_date DESC.

    Thread Starter aosmichenko

    (@aosmichenko)

    Found the issue, The code from other thread, needs to be slightly updated

    add_action('init', 'ir_search_hook');
    function ir_search_hook() {
    	remove_filter( 'posts_search_orderby', 'relevanssi_light_posts_search_orderby', 10, 2 );
    	add_filter( 'posts_search_orderby', 'rl_posts_search_orderby', 10, 2 );
    	function rl_posts_search_orderby( $orderby, $query ) {
    		if ( isset( $query->query['s'] ) ) {
    			$orderby = 'post_date DESC';
    		}
    		return $orderby;
    	}
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Order by date not working’ is closed to new replies.