WordPress.org

Support

Support » Plugins and Hacks » The Events Calendar » [Plugin: The Events Calendar] Show Upcoming Events of Specific Category

[Plugin: The Events Calendar] Show Upcoming Events of Specific Category

  • 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/

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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 🙂

    This is awesome, thanks for the help!

    Glad to be of service 🙂

    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

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: The Events Calendar] Show Upcoming Events of Specific Category’ is closed to new replies.
Skip to toolbar