List Specific Events On A Page

Home Forums Calendar Products Events Calendar PRO List Specific Events On A Page

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #968881
    Chris Chung
    Participant

    I have a page where I want to list event title and dates of specific categories.
    So far I have it showing the titles of all events. I’m trying to figure out how to specify the category,
    Then I will worry about posting the date field. Thanks!

    Here is what I have so far:

    <?php 
    	$args = array( 'post_type'=> 'tribe_events');
    	$catposts = get_posts($args); foreach($catposts as $post) : 
    ?>
    <article>
    	<p>
    		<?php 
    			echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
    		?> 
    	</p>
    </article>
    #968885
    Chris Chung
    Participant

    Attempting:

    <?php 
    	$cat = 75;
    	$args = array( 'post_type'=> 'tribe_events', 'category__in' => array($cat));
    	$posts = get_posts($args); 
    	if ($posts) {
    		foreach($posts as $post) {
    			setup_postdata($catposts);
    ?>
    	<article>
    		<p>
    		<?php 
    				echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
    		?> 
    		</p>
    	</article>
    <?php  
    		}
    	}
    ?>	
    #968906
    Barry
    Member

    Hi there!

    I’d be happy to point you in the right direction if I can – but I do want to note first of all that custom code is typically not something we can offer a great deal of support for.

    With that out of the way, it’s worth noting that events do not use the same categories as blog posts – they use a separate, event-specific type of category. Here’s a couple of things you can try:

    • Switch to tribe_get_events() instead of get_posts()
    • If you use this function, you don’t need to specify the post type
    • You may wish to pass a tribe_events_cat argument in place of category__in
    • Additionally, depending on the sort of results you are hoping for, you may wish to provide an eventDisplay argument set to list

    Last but not least, be sure to check out this helpful knowledgebase article:

    heeventscalendar.com/knowledgebase/using-tribe_get_events

    Good luck!

    #969056
    Chris Chung
    Participant

    Thanks a bunch Barry! That page you linked is what I was looking for.
    Now I just need to find the date field and post that as well.

    #969163
    Barry
    Member

    Check out tribe_get_start_date() 🙂

    #969167
    Chris Chung
    Participant

    Thanks, already got it with this:

    $date = new DateTime($event->post_date);
    echo $date->format('l F j , Y');
    #969173
    Barry
    Member

    Ah, ok – if its the publication date you want for the event that probably isn’t a bad way to go.

    Glad you’re all sorted 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘List Specific Events On A Page’ is closed to new replies.