Support » Plugin: The Events Calendar » Template tags & conditionals outside of the loop

  • Resolved filip.jnc

    (@filipjnc-1)


    Dear Modern Tribe dev team,

    I’ve been using your plugin for a while and I must say it’s top notch. Thanks for supporting the free version just as well as the pro one.

    Not long ago, I started developing a theme that should fully support TEC. The plugin’s conditionals and template tags that you made available are very handy, however, some of them seem work incorrectly outside of the loop.

    Conditionals
    Starting with the conditionals, I’ve encountered issues particularly with tribe_is_event(), tribe_is_venue(), and tribe_is_organizer(). I’ve been using them in the header section and they all returned false where they had to return true.
    After examining WP documentation, I ended up using is_singular(‘tribe_events’), is_singular(‘tribe_venue’), and is_singular(‘tribe_oganizer’) respectively. It seems to work just fine. It would be cool to have this working by default using the plugin’s own conditionals.

    Template tags
    Because TEC seems to create temporary phantom pages (ID=0) to display its templates, some template tags are not working properly outside of the loop. In my particular case, I had to filter wp_title on some TEC pages to display the event’s/venue’s/organizer’s title as the page title. First, I tried tribe_events_title() on single event pages. However, what it always echoed no matter what event I opened was “Upcoming events”.
    I had to come up with my own solution, and after digging in WP docs I was able to echo the actual event/venue/organizer title outside of the loop. First, I had to use the global variable $wp_query, because it seemed that TEC does some alterations there. Second, I iterated through the posts object until $post->post_type matched what I needed (i.e. tribe_events, tribe_venue, or tribe_organizer). Goes without saying, I would like to have this as a template tag that works outside of the loop as well. Here’s my code:

    global $wp_query;
    
    if( is_singular('tribe_events') ) { // Single Events
            foreach ( $wp_query->posts as $post ) :
    		if ( $post->post_type === 'tribe_events' )
    			$title = $post->post_title;
    	endforeach;
    } elseif( is_singular('tribe_venue') ) { // Single Venues
        foreach ( $wp_query->posts as $post ) :
    	if ( $post->post_type === 'tribe_venue' )
    		$title = $post->post_title;
        endforeach;
    } elseif( is_singular('tribe_organizer') ) { // Single Organizers
    	foreach ( $wp_query->posts as $post ) :
    		if ( $post->post_type === 'tribe_organizer' )
    			$title = $post->post_title;
    	endforeach;
    }

    Thanks for your time and I’m looking forward to your feedback.

    Filip

    https://wordpress.org/plugins/the-events-calendar/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Template tags & conditionals outside of the loop’ is closed to new replies.