Home › Forums › Calendar Products › Community Events › Community Event custom query
- This topic has 3 replies, 2 voices, and was last updated 11 years, 5 months ago by
Brian.
-
AuthorPosts
-
November 18, 2014 at 11:52 am #889527
Victor
ParticipantHello,
I am trying to build a shortcode that displays a list of community events. Can you tell me what args should I give the query? How do I differentiate between admin and community added events without the use of event categories?
For example, the code below displays both admin and community added events:$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $upcoming = new WP_Query(); $upcoming->query( array( 'post_type'=> 'tribe_events', 'eventDisplay' => 'upcoming', 'posts_per_page' => 3, 'paged' => $paged ) );Thanks.
November 18, 2014 at 4:36 pm #889805Brian
MemberHi,
That is a good question.
There is the meta field:
_EventOrigin
Which will have
community-events
in it if the event comes from the Community Events Form
Does that help?
November 19, 2014 at 1:24 am #890283Victor
ParticipantThanks Brian, that did the trick.
For all of you who want to display community events on a particular page here is a shortcode for that (add to functions.php):add_shortcode('community_gatherings', 'community_gatherings_shortcode_query'); function community_gatherings_shortcode_query($atts){ global $post; $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $upcoming = new WP_Query(); $upcoming->query( array( 'post_type'=> 'tribe_events', 'eventDisplay' => 'upcoming', 'posts_per_page' => 3, 'paged' => $paged, 'meta_query' => array( array( 'key' => '_EventOrigin', 'value' => array('community-events'), 'compare' => 'IN', ), ), ) ); $output = ''; $output .= '<h3 class="upcoming-list-title"><span>Latest On The Road Gatherings with Craig Johnson</span></h3>'; $output .= '<div class="row">'; if ($upcoming->have_posts()) : while ($upcoming->have_posts()) : $upcoming->the_post(); $output .= '<div class="col-lg-4">'; $output .= '<div class="gathering">'; if ( has_post_thumbnail() ) { $output .= '<div class="gathering-image">'.get_the_post_thumbnail().'</div>'; } $output .= '<h2 class="gathering-title">'.get_the_title().'</h2>'; $output .= '<div class="gathering-meta"><span class="gathering-date">'; if (tribe_event_is_all_day()){ $output .= tribe_get_start_date($post->ID).' - all day'; } else { $output .= tribe_get_start_date($post->ID); $output .= ' - '; if (tribe_get_start_date($post->ID) !== tribe_get_end_date($post->ID) ){ $output .= tribe_get_end_date($post->ID); } else { $output .= tribe_get_end_time($post->ID); } } $output .= '</span></div>'; $output .= '<div class="gathering-excerpt">'.get_the_excerpt().'</div>'; $output .= 'Join this Gathering <i class="fa fa-chevron-right"></i>'; $output .= '</div></div>'; endwhile; $output .= '<div class="col-lg-12"><div class="gathering-nav">'.etheme_pagination($upcoming, $paged).'</div></div>'; endif; $output .= '</div>'; wp_reset_query(); return html_entity_decode($output); }Then in your page editor add:
[community_gatherings]
My client wanted to replace events with gatherings, thus the term.
Hope it helps.November 19, 2014 at 5:18 am #890499Brian
MemberGreat thanks for sharing the coding. I am sure someone will find that useful as well or be able to adapt the coding to fit what they would like.
I am going to close this ticket, but if you need anything else related to this topic or another please post a new topic on the forum and we can help you out.
Thanks
-
AuthorPosts
- The topic ‘Community Event custom query’ is closed to new replies.
