apply_filters( 'relevanssi_missing_sort_key', string $key_value, string $key_name );

Fills in the missing sort key in case a custom field sorting has a missing key.


(string) The sorting field value.

(string) The name of the custom field.

More information

In some cases the sorting method may not have values for all posts (for example when sorting by menu_order). If you still want to use a sorting method like this, you can use this function to fill in a default value.

A good default value for numeric fields sorted in ascending order (like menu_order) is PHP_INT_MAX, which is the largest possible number. When sorting in descending order, a decent default value is 0.

add_filter( 'relevanssi_missing_sort_key', 'rlv_default_key', 10, 2 );
 * Add default values.
 * @param string $value The sorting field value.
 * @param string $key   The sorting field name.
 * @return string The sorting field value.
function rlv_default_key( $value, $key ) {
    if ( 'menu_order' === $key ) {
        $value = PHP_INT_MAX;
    return $value;