tribe_is_event() failing on events without categories

Home Forums Calendar Products Events Calendar PRO tribe_is_event() failing on events without categories

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #973538
    Ken Charity
    Participant

    I have several categories set up, some without events associated to them.

    if ( tribe_is_event() ) {                 
    
    	if ( is_singular( 'tribe_events' ) ) { // we are on a single event page
    
    		echo 'Events Calendar Single Event';
    
    	} elseif ( tribe_is_month() && !is_tax() ) { // Month View Page
    
    		echo 'Events Calendar Month';
    
    	} elseif ( tribe_is_month() && is_tax() ) { // Month View Category Page
    
    		echo 'Events Calendar Category';
    	}
    
    } elseif ( is_archive() ) {
    
    	echo 'Archives';
    
    }

    On month category page with events I get ‘Events Calendar Category’ output, with no events I get ‘Archives’

    If I remove the tribe_is_event() check and use it like this:

    if ( is_singular( 'tribe_events' ) ) { // we are on a single event page
    
    	echo 'Events Calendar Single Event';
    
    } elseif ( tribe_is_month() && !is_tax() ) { // Month View Page
    
    	echo 'Events Calendar Month';
    
    } elseif ( tribe_is_month() && is_tax() ) { // Month View Category Page
    
    	echo 'Events Calendar Category';
    
    } elseif ( is_archive() ) {
    
    	echo 'Archives';
    
    }

    I get ‘Events Calendar Category’ output on the category month view with and with out events for that particular category as expected.

    Why is checking if the page is an events page failing on categories without events tied to them?

    #973548
    George
    Participant

    Hey Ken,

    tribe_is_event() only looks for whether a single item is of the Tribe Events post type or not, so it seems to me like something like this might work a little better for your needs here:

    
    
    if ( tribe_is_event() ) {                 
    
    	if ( is_singular( 'tribe_events' ) ) { // we are on a single event page
    
    		echo 'Events Calendar Single Event';
    	} 
    
    } elseif ( tribe_is_month() ) {
            
            if ( ! is_tax() ) { // Month View Page
    		
                    echo 'Events Calendar Month';
    
    	} else { // Month View Category Page
    		
                    echo 'Events Calendar Category';
    	}
    
    } elseif ( is_archive() ) {
    
    	echo 'Archives';
    
    }
    

    What do you find when you try this?

    #973554
    Ken Charity
    Participant

    Ah ok thanks for clarifying that. That would be similar to the second code snippet I wrote minus the check. I assume that Venues and Organizers can also fall in that tribe_is_event() check as well?

    I was really trying to use tribe_is_event() as a wrapper for all ECP related pages. Is there such a helper function that exists?

    #973693
    George
    Participant

    Hi Ken,

    There is not a wrapper for all ECP-related pages.

    As for venues and organizers, tribe_is_event() will return false for those because those things are not events.

    To check for those things, there are equivalents however. They are tribe_is_venue() and tribe_is_organizer().

    I hope that helps!

    Cheers,
    George

    #973767
    Ken Charity
    Participant

    Thanks for the info.

    #974381
    George
    Participant

    No problem!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘tribe_is_event() failing on events without categories’ is closed to new replies.