Hi Lee
You can use the pre_get_posts filter
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 );
-
This reply was modified 6 years, 9 months ago by
Merv Barrett. Reason: updated function to add is_main_query()
-
This reply was modified 6 years, 8 months ago by
Merv Barrett. Reason: added !is_admin() to prevent effecting the admin
-
This reply was modified 6 years, 8 months ago by
Merv Barrett.