I have created a real estate theme, and for each property there is a property listing expiry date after which the property no longer shows on the site. Each property is a custom Properties post type. The code I use to only use live properties is;
function live_properties_only( $query ) {
if ( ! is_main_query() ) {
$today = date('Ymd');
$meta_query = array (
'post_type' => 'properties',
'meta_query' => array(
'key' => 'date_listing_expires',
'compare' => '>',
'value' => $today,
),
);
$query->set('meta_query',$meta_query);
}
}
add_action( 'pre_get_posts', 'live_properties_only' );
This is in the functions.php file, the only problem is that is prevents regular blog posts from showing. How can I resolve this so blog posts show and only un-expired properties also show.
wp_reset_query();
after your if statement – Spartacus Feb 10 '17 at 17:00