custom WordPress Events Manager event tag archive page
Using the Events Manager WordPress plugin at work, I noticed that the event tag archive pages showed only current and upcoming events with a given tag. I wanted them to show all events, including past events, with the tag. I made a custom loop to accomplish this, within the Genesis framework. Create a file called taxonomy-event-tags.php in your Genesis child theme, with the following contents:
PHP
<?php
/**
* This file adds the Taxonomy - Event Tags template to our Child Theme.
*/
/*
Template Name: Taxonomy - Event Tags
*/
remove_action('genesis_loop', 'genesis_do_loop'); // remove genesis loop
add_action('genesis_loop', 'event_tag_custom_loop'); // add the special loop
function event_tag_custom_loop() {
global $wp_query;
$term = $wp_query->get_queried_object();
$loop = new WP_Query(array(
'post_type' => 'event',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'event-tags',
'field' => 'tag_ID',
'terms' => array($term->term_id)
)
),
// Order by event start date, most recent at the top
'meta_key' => '_event_start_date',
'orderby' => 'meta_value',
'order' => DESC
));
?>
<div class="events-tag-archive-list">
<?php while ($loop->have_posts()) : $loop->the_post();
$custom_fields = get_post_custom($post->ID);
$event_start_date = $custom_fields['_event_start_date'][0];
?>
<div id="post-<?php the_ID(); ?>" class="event post type-post">
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent link to <?php the_title(); ?>">
<?php the_title(); ?>
</a>
</h2>
<div class="post-info">
<span class="date event-start-date">
Event begins <a href="/link-to-your-events-page/<?php echo $event_start_date; ?>" title="View events on this day"><?php echo $event_start_date; ?></a>
</span>
<?php edit_post_link('Edit', '(', ')'); ?>
</div>
<div class="entry-content">
<?php the_excerpt(); ?>
</div>
<div class="post-meta">
<span class="tags">
<?php the_terms($post->ID, 'event-tags', 'Tags: ', ', ', ' '); ?>
</span>
</div>
</div>
<?php endwhile; ?>
</div>
<?php
}
/**
* This file adds the Taxonomy - Event Tags template to our Child Theme.
*/
/*
Template Name: Taxonomy - Event Tags
*/
remove_action('genesis_loop', 'genesis_do_loop'); // remove genesis loop
add_action('genesis_loop', 'event_tag_custom_loop'); // add the special loop
function event_tag_custom_loop() {
global $wp_query;
$term = $wp_query->get_queried_object();
$loop = new WP_Query(array(
'post_type' => 'event',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'event-tags',
'field' => 'tag_ID',
'terms' => array($term->term_id)
)
),
// Order by event start date, most recent at the top
'meta_key' => '_event_start_date',
'orderby' => 'meta_value',
'order' => DESC
));
?>
<div class="events-tag-archive-list">
<?php while ($loop->have_posts()) : $loop->the_post();
$custom_fields = get_post_custom($post->ID);
$event_start_date = $custom_fields['_event_start_date'][0];
?>
<div id="post-<?php the_ID(); ?>" class="event post type-post">
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent link to <?php the_title(); ?>">
<?php the_title(); ?>
</a>
</h2>
<div class="post-info">
<span class="date event-start-date">
Event begins <a href="/link-to-your-events-page/<?php echo $event_start_date; ?>" title="View events on this day"><?php echo $event_start_date; ?></a>
</span>
<?php edit_post_link('Edit', '(', ')'); ?>
</div>
<div class="entry-content">
<?php the_excerpt(); ?>
</div>
<div class="post-meta">
<span class="tags">
<?php the_terms($post->ID, 'event-tags', 'Tags: ', ', ', ' '); ?>
</span>
</div>
</div>
<?php endwhile; ?>
</div>
<?php
}
genesis();