Menu not showing while using filter hook for custom posts
-
I am developing a coupon website (http://www.mysmartqpons.com/). I have a custom post type named
offerand each event has a meta value namedoffer_end_date.offerpost type has two custom taxonomyoffer_categoryandoffer_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.phpandtaxonomy-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?
The topic ‘Menu not showing while using filter hook for custom posts’ is closed to new replies.