The code below is suppose to display all posts with "featured_listing" meta key above all of the standard posts.
When the below code is in the functions.php, it hides all posts without "featured_listing" meta. Instead of showing them below the featured listings.
function custom_special_sort( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
// if is this the main query and is this post type of business
if ( (is_post_type_archive('business') ) || (is_tax ('location') ) ) {
// order results by the meta_key 'featured_listing'
$query->set( 'meta_key', 'featured_listing' );
$query->set( 'orderby', 'featured_listing' );
$query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'custom_special_sort' );