I am developing a coupon website (http://ift.tt/1Dqez3o). I have a custom post type named offer and each event has a meta value named offer_end_date.
offer post type has two custom taxonomy offer_category and offer_store.
On the homepage I'm trying to show a section named latest section where latest 6 offers will be shown.
I have two different files to display the events for both the taxonomies (i.e. taxonomy-offer_category.php and taxonomy-offer_store.php)
In all these pages (including search result page), I want to show only today's offers and upcoming offers. So I added a filter hook.
function rel_exclude_expired_offers($query) {
if( $query->get( 'post_type' ) == 'offer' || is_tax() || is_search() )
{
$meta_query = array(
array(
'key' => 'offer_end_date',
'value' => mktime(0, 0, 0, date("n"), date("j"), date("Y")),
'compare' => '>='
)
);
$query->set( 'meta_query', $meta_query );
}
}
add_filter('pre_get_posts', 'rel_exclude_expired_offers');
The code is working fine, but in category, location (taxonomy pages) and search pages menu is not showing.
If I remove || is_tax() || is_search() from $query->get( 'post_type' ) == 'offer' || is_tax() || is_search(), menu shows properly, but the filter does not work in taxonomy and search pages.
Where's my mistake?
Aucun commentaire:
Enregistrer un commentaire