• Hi,
    I have this plugin installed in a library´s website.
    When I search a book, i.e “by title” I´d like to see the results ordered by date (from newest to oldest). How should I configure it?

    Thanks

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

    (@msaari)

    If you want all the searches to return posts by date, just change the setting in the Relevanssi settings page.

    If you want only some searches sorted by date, you can use the orderby parameter. Set it to post_date.

    For example, you could have a dropdown like this on your search form:

    <select name="orderby">
        <option value="post_date">Date</option>
        <option value="relevance">Relevance</option>
    </select>
    Thread Starter user2015

    (@user2015)

    Thanks for your answer Mikko.
    I think I wasn´t clear. I need to order them by the date in which each book was published (ACF field), not the date in which each book was posted.

    That is:
    Title: XXXX
    Author: XXXX
    Date: 2016

    Thanks for your help

    Plugin Author Mikko Saari

    (@msaari)

    Change the select to

    <select name="orderby">
        <option value="publication_date">Date</option>
        <option value="relevance">Relevance</option>
    </select>

    and add

    add_filter( 'relevanssi_orderby', 'publication_date_orderby' );
    function publication_date_orderby( $orderby ) {
    	if ( 'publication_date' === $orderby ) {
    		global $wp_query;
    		$orderby = 'meta_value_num';
    		$wp_query->query_vars['meta_key'] = 'XXX';
    	}
    	return $orderby;
    }

    to your functions.php. Just change “XXX” to the name of the date field. There’s a small catch, though: this doesn’t work with the current version of Relevanssi. It will work with the next version, and also with the current version, if you replace the lib/sorting.php file with this one: https://github.com/msaari/relevanssi/blob/master/lib/sorting.php

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Results order’ is closed to new replies.