• Resolved sapna185

    (@sapna185)


    Hi,

    I want to add sort by: dropdown filter on the search result page.

    The dropdown will have options like, Relevance, Most recent(order by post updated date) and oldest.

    on clicking any of the above options, the should get the relevant posts.

    Is this possible? if yes, how can I do that?

    Thank you.

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

    (@msaari)

    Add this to your search form:

    <select name="orderby">
      <option value="relevance">Relevance</option>
      <option value="post_date">Recent</option>
      <option value="post_date_oldest">Oldest</option>
    </select>

    And then you need this in your theme functions.php to get the Oldest to work:

    add_filter( 'relevanssi_modify_wp_query', function( $q ) {
      if ( 'post_date_oldest' === $q->get( 'orderby' ) ) {
        $q->set( 'orderby', array( 'post_date' => 'asc') );
      }
      return $q;
    } );
    Thread Starter sapna185

    (@sapna185)

    Hello Mikko,

    Thank you so much for your prompt reply. will try this code.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sort by dropdown on result page’ is closed to new replies.