Excluding Sold and Leased from Property Loop pre_get_posts
Using the WordPress pre_get_posts filter you can alter the default post type archive page and exclude sold or leased listings.
function my_property_filter($query) {
// Do nothing if is dashboard/admin or doing search
if ( is_admin() || epl_is_search() ) {
return;
}
// The query to only show 'current' listings
$meta_query = array(
array(
'key'=>'property_status',
'value'=>'current',
'compare'=>'==',
),
);
// Only show current listings on your main /property/ page
if ( $query->is_main_query() && is_post_type_archive( 'property' ) ) {
$query->set('meta_query',$meta_query);
return;
}
// Only show current listings on your main /rental/ page
if ( $query->is_main_query() && is_post_type_archive( 'rental' ) ) {
$query->set('meta_query',$meta_query);
return;
}
}
add_action( 'pre_get_posts', 'my_property_filter' , 20 );
Alternatively you can use the [listing] shortcode and create a specific page to display your current, sold, leased listings.