Home › Forums › Calendar Products › Events Calendar PRO › Pull in latest featured event.
- This topic has 17 replies, 2 voices, and was last updated 6 years, 9 months ago by Kari Acker.
-
AuthorPosts
-
June 15, 2017 at 7:09 am #1298441Kari AckerParticipant
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>
June 15, 2017 at 10:00 pm #1298950CliffMemberHi, 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.
June 16, 2017 at 6:51 am #1299080Kari AckerParticipantHi,
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.
June 16, 2017 at 11:43 pm #1299524CliffMemberI 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?
June 21, 2017 at 12:31 pm #1301268Kari AckerParticipantIm 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’,
);
}
`June 21, 2017 at 2:13 pm #1301348CliffMemberYou can use the highlighted portion of the code that I linked to as part of tribe_get_events(), get_posts(), or WP_Query.
June 21, 2017 at 2:28 pm #1301355Kari AckerParticipantHi,
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
-DanJune 21, 2017 at 3:04 pm #1301372CliffMemberWhoops, 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.
June 23, 2017 at 7:17 am #1302250Kari AckerParticipantHi,
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
-DanJune 26, 2017 at 8:40 pm #1308154CliffMemberTribe__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.
June 27, 2017 at 11:15 am #1309210Kari AckerParticipantHi, 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>
June 28, 2017 at 9:48 am #1310282CliffMemberTo 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)?
June 29, 2017 at 9:20 am #1312082Kari AckerParticipantHi,
Im looking for the next upcoming featured event (based on start date).
Thanks
-DanJune 29, 2017 at 2:18 pm #1312737CliffMemberGive this a shot, Kari/Dan:
https://gist.github.com/cliffordp/1b8c808efa4256ebcef2d8805f069595
Please let me know how this goes for you.
July 6, 2017 at 1:12 pm #1317088Kari AckerParticipantThanks 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>
-
AuthorPosts
- The topic ‘Pull in latest featured event.’ is closed to new replies.