Pull in latest featured event.

Home Forums Calendar Products Events Calendar PRO Pull in latest featured event.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #1298441
    Kari Acker
    Participant

    Hi,

    Im trying to pull in the latest event that is marked with your “featured” event. I just wanted to pull in a single event. Here is the current code im using but it just seems to be pulling in the latest event and ignoring the “featured” part. Any idea where im going wrong?

    
    		<div class="small-12 medium-6 large-4 columns">
    			<?php $events = tribe_get_events( array( 'posts_per_page' => 1, 'orderby' => 'meta_value', 'order' => 'DESC' , 'terms' => 'feature_event' ) );
    				foreach ( $events as $event ) {
    					$terms = get_the_terms( $event->ID, 'tribe_events_cat' ); ?>
    						<p class="home-cat"><?php foreach ( $terms as $term ) { echo $term->name; } ?></p>
    						<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<?php echo tribe_event_featured_image( $event->ID, 'home-blog', true ); ?>
    						</a>
    						<div class="home-news-content clearfix" data-equalizer-watch>
    							<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<h2><?php echo $event->post_title; ?></h2></a>
    							<p><?php echo $event->post_excerpt; ?></p>
    							<a class="home-read-more" href="<?php echo tribe_get_event_link( $event->ID ) ?>">Read More</a>
    						</div>
    					<?php wp_reset_postdata();
    				} ?>
    		</div>
    	</div>
    
    #1298950
    Cliff
    Member

    Hi, Kari.

    You can reference the code snippet at https://theeventscalendar.com/knowledgebase/integrating-events-calendar-slider-revolution-essential-grid/#revslider-custom-queries to see how to query for Featured Events.

    Please let me know if you have any follow-up questions on this topic.

    #1299080
    Kari Acker
    Participant

    Hi,

    So im still a little confused. Im still somewhat new with PHP and that seems like a really complex query just to pull in the featured event.

    There is no way just to add it to my $events array to pull it in? I would rather not pull this in with a shortcode from my function. I would just like to have everything right in my original query.

    #1299524
    Cliff
    Member

    I was referring to this part of the included snippet: https://gist.github.com/cliffordp/30ac2152a8264ef27235b46b7d16332d#file-functions-php-L43-L47, not anything specific to that article’s overall topic.

    Is this clearer now?

    #1301268
    Kari Acker
    Participant

    Im still a little confused. I have the image pulling in already. Would I have to use this part in my query?`

    `

    // is a Featured Event (requires The Events Calendar version 4.4+ from January 9, 2017)
    if ( class_exists( ‘Tribe__Events__Main’ )
    && class_exists( ‘Tribe__Events__Featured_Events’ )
    && Tribe__Events__Main::POSTTYPE === $query[‘post_type’]
    ) {
    $meta_query[] = array(
    ‘key’ => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY,
    ‘compare’ => ‘EXISTS’,
    );
    }
    `

    #1301348
    Cliff
    Member

    You can use the highlighted portion of the code that I linked to as part of tribe_get_events()get_posts(), or WP_Query.

    #1301355
    Kari Acker
    Participant

    Hi,

    So your highlighted part is talking about just the featured image. I already have that pulling in. Im just trying to get the “featured event” to pull in.

    Thanks
    -Dan

    #1301372
    Cliff
    Member

    Whoops, you’re right; I highlighted the wrong portion before; you’re right.

    https://gist.github.com/cliffordp/30ac2152a8264ef27235b46b7d16332d#file-functions-php-L54-L57 is what I meant for you to include in your query.

    If you don’t get things working, please provide me the full custom code you’re trying to implement.

    #1302250
    Kari Acker
    Participant

    Hi,

    Im sorry but im still having issues getting this to work. Here is my code.

    
    		<div class="small-12 medium-6 large-4 columns">
    			<?php $events = tribe_get_events( array( 'posts_per_page' => 1, 'orderby' => 'meta_value', 'order' => 'DESC' , 'key' => 'Tribe__Events__Featured_Events::FEATURED_EVENT_KEY' , 'compare' => 'EXISTS', ) );
    				foreach ( $events as $event ) {
    					$terms = get_the_terms( $event->ID, 'tribe_events_cat' ); ?>
    						<p class="home-cat"><?php foreach ( $terms as $term ) { echo $term->name; } ?></p>
    						<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<?php echo tribe_event_featured_image( $event->ID, 'home-blog', true ); ?>
    						</a>
    						<div class="home-news-content clearfix" data-equalizer-watch>
    							<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<h2><?php echo $event->post_title; ?></h2></a>
    							<p><?php echo $event->post_excerpt; ?></p>
    							<a class="home-read-more" href="<?php echo tribe_get_event_link( $event->ID ) ?>">Read More</a>
    						</div>
    					<?php wp_reset_postdata();
    				} ?>
    		</div>

    Please let me know what I can do to get this working.

    Thanks
    -Dan

    #1308154
    Cliff
    Member

    Tribe__Events__Featured_Events::FEATURED_EVENT_KEY shouldn’t be in quotes.

    Also, you don’t need wp_reset_postdata() because you’re using tribe_get_events()

    Please let me know how this goes for you.

    #1309210
    Kari Acker
    Participant

    Hi, So this is what i ended up with and its still just pulling in the latest event.

    
    		<div class="small-12 medium-6 large-4 columns">
    			<?php $events = tribe_get_events( array( 'posts_per_page' => 1, 'orderby' => 'meta_value', 'order' => 'DESC' , 'key' => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY , 'compare' => 'EXISTS' ) );
    				foreach ( $events as $event ) {
    					$terms = get_the_terms( $event->ID, 'tribe_events_cat' ); ?>
    						<p class="home-cat"><?php foreach ( $terms as $term ) { echo $term->name; } ?></p>
    						<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<?php echo tribe_event_featured_image( $event->ID, 'home-blog', true ); ?>
    						</a>
    						<div class="home-news-content clearfix" data-equalizer-watch>
    							<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<h2><?php echo $event->post_title; ?></h2></a>
    							<p><?php echo $event->post_excerpt; ?></p>
    							<a class="home-read-more" href="<?php echo tribe_get_event_link( $event->ID ) ?>">Read More</a>
    						</div>
    			<?php } ?>
    		</div>
    #1310282
    Cliff
    Member

    To be clear, are you wanting to get the latest published featured event or are you wanting the next upcoming featured event (based on start date)?

    #1312082
    Kari Acker
    Participant

    Hi,

    Im looking for the next upcoming featured event (based on start date).

    Thanks
    -Dan

    #1312737
    Cliff
    Member

    Give this a shot, Kari/Dan:

    https://gist.github.com/cliffordp/1b8c808efa4256ebcef2d8805f069595

    Please let me know how this goes for you.

    #1317088
    Kari Acker
    Participant

    Thanks for looking into this for me. Here is the code i ended up with and with this code nothing get pulled in at all. Do you think this is something wrong with how I integrated your code in with mine?

    
    		<div class="small-12 medium-6 large-4 columns">
    			<?php $args = array(
    			'eventDisplay'   => 'custom',
    			'posts_per_page' => 1,
    			'meta_query'     => array(
    				'relation'   => 'AND',
    				'featured'   => array(
    					'key'     => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY,
    					'compare' => 'EXISTS',
    				),
    				'start_date' => array(
    					'key'     => '_EventStartDate',
    					'value'   => current_time( 'mysql' ),
    					'compare' => '>=',
    					'type'    => 'DATETIME',
    				),
    			),
    			'orderby'        => array(
    				'start_date' => 'ASC',
    			),
    		);
    				foreach ( $events as $event ) {
    					$terms = get_the_terms( $event->ID, 'tribe_events_cat' ); ?>
    						<p class="home-cat"><?php foreach ( $terms as $term ) { echo $term->name; } ?></p>
    						<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<?php echo tribe_event_featured_image( $event->ID, 'home-blog', true ); ?>
    						</a>
    						<div class="home-news-content clearfix" data-equalizer-watch>
    							<a href="<?php echo tribe_get_event_link( $event->ID ) ?>">
    							<h2><?php echo $event->post_title; ?></h2></a>
    							<p><?php echo $event->post_excerpt; ?></p>
    							<a class="home-read-more" href="<?php echo tribe_get_event_link( $event->ID ) ?>">Read More</a>
    						</div>
    			<?php } ?>
    		</div>
    
Viewing 15 posts - 1 through 15 (of 17 total)
  • The topic ‘Pull in latest featured event.’ is closed to new replies.