WordPress.org

Ready to get started?Download WordPress

Forums

The Events Calendar
Show Upcoming Events of Specific Category (7 posts)

  1. Chris
    Member
    Posted 2 years ago #

    I had my site in the past configured to show the upcoming events of a specific category in a widget but with the update of The Events Calendar it stopped working.

    In the past I was using this bit of code which output the upcoming events of a category (so it didn't show every event in the calendar, just the ones in that category).

    <ul>
    <?php $recent = new WP_Query("cat=11&showposts=5"); while($recent->have_posts()) : $recent->the_post();?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <?php the_title(); ?>
    </a></li>
    <?php endwhile; ?>
    </ul>

    Now it no longer works. Does anyone know how I would achieve the same thing with the new version of The Events Calendar?

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. jonahcoyote
    Member
    Posted 2 years ago #

    Hey Chris, if you want to use WP_Query you have to pass in a tax_query argument to the query because the plugin now uses taxonomies for categories. So something like this is what you would want to use:

    <ul>
    <?php
    $args = array(
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'tribe_events_cat',
    			'field' => 'slug',
    			'terms' => 'my_cat_slug'
    		)
    	),
           'posts_per_page' => 5
    );
    $recent = new WP_Query( $args );
    while($recent->have_posts()) : $recent->the_post();?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <?php the_title(); ?>
    </a></li>
    <?php endwhile; ?>
    </ul>

    That should do it :)

  3. jonahcoyote
    Member
    Posted 2 years ago #

  4. Chris
    Member
    Posted 2 years ago #

    This is awesome, thanks for the help!

  5. jonahcoyote
    Member
    Posted 2 years ago #

    Glad to be of service :)

  6. Radmacdaddy
    Member
    Posted 2 years ago #

    jonahcoyote: do I have to create a template for each page I want that code in?

    If I, say, duplicate a template and paste that snippet in with my taxonomy/category where should I place that snippet.

    Cheers

  7. jonahcoyote
    Member
    Posted 2 years ago #

    Hey Radmacdaddy, no. The code above was intended to modify an existing custom query that was in a widget somewhere but it could have been the home page, another specific page, a category or anything really. Custom queries can go anywhere. In your theme you will need to figure out where you need it to go because all themes are different. My suggestion would be to pop it in some different files and see what happens and adjust accordingly. Hopefully that answers your question.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic