apply_filters( 'relevanssi_comparison_order', array $order )

Provides a sorting order for custom sorting.


(array) An array of key values as keys and their sorting order as values.

More information

If you specify post_type as the sorting key, Relevanssi will use this filter hook to get the sorting order. You can also use the filter hook relevanssi_sort_compare to specify the compare method of filter to use this sorting for other keys.

If you want, for example, post type post first in the result, then post type page and finally, the post type news last, you can do:

add_filter( 'relevanssi_comparison_order', function( $order ) {
  $order = array(
    'post' => 0,
    'page' => 1,
    'news' => 2,
  return $order;
} );

Now when you specify orderby=post_type, Relevanssi will use this order to sort the posts.

add_filter( 'relevanssi_modify_wp_query', function( $query ) {
    $query->set( 'orderby', array( 'post_type' => 'asc', 'relevanssi' => 'desc' ) );
    return $query;
} );

Any values that don’t have a specified sorting order in the array are sorted last in the results.