FacetWP – when sorting by rating, prevent results with no ratings from disappearing

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

function fwp_preserve_unrated_posts( $query ) {
if ( ‘rating’ == $query->get( ‘meta_key’ ) ) {
$query->set( ‘meta_query’, array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘rating’,
‘compare’ => ‘EXISTS’,
),
array(
‘key’ => ‘rating’,
‘compare’ => ‘NOT EXISTS’
)
) );
}
}
add_filter( ‘pre_get_posts’, ‘fwp_preserve_unrated_posts’ );
{{/gist}}