• Hi,

    As the docs stated,if I want to sort search results by date, then I can use:

    <?php echo '<p><a href="' . get_bloginfo('url') . '?s=' . get_search_query() . '&orderby=post_date&order=desc">Order results by date<a></p>'; ?>

    Since each of my post has a custom field named as post_views_count to keep track of the number of views of this post, so my question is there any way I can sort the search results by this custom field? I’ve tried:

    <?php echo '<p><a href="' . get_bloginfo('url') . '?s=' . get_search_query() . '&orderby=post_views_count&order=desc">Order results by date<a></p>'; ?>

    but it does not work. Thank you very much in advance 🙂

    https://wordpress.org/plugins/relevanssi/

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

    (@msaari)

    No, it doesn’t work like that.

    You can use relevanssi_hits_filter hook to do whatever you want to the search results, so you can sort the results there.

Viewing 1 replies (of 1 total)
  • The topic ‘Order by custom field’ is closed to new replies.