Home › Forums › Calendar Products › Events Calendar PRO › How to show events for only 1 month and 1 category?
- This topic has 6 replies, 5 voices, and was last updated 10 years, 9 months ago by
Support Droid.
-
AuthorPosts
-
July 11, 2012 at 10:21 am #21960
Kenny
MemberI’d like to embed the Events Calendar calendar view of events into a post and have it show only events that are in a certain category and that occur in August.
I saw in the FAQ that this can be achieved using filters, but I’m at a loss as to how to go about using them.
Any help is greatly appreciated, thanks!
July 11, 2012 at 4:32 pm #21975Jonah
ParticipantHi Kenny,
You can only embed the calendar via PHP code, we don’t have any shortcodes. So, you’ll want to somehow get this code into your theme’s single.php file (for single posts) and limit it to only the specific posts you want via conditionals. The embeds you can use are the following:
include('wp-content/plugins/the-events-calendar/views/table.php');
…or…
include('wp-content/plugins/the-events-calendar/views/gridview.php');
Then, to filter out specific categories you’ll want to use the following in your theme’s functions.php file:
add_action( 'pre_get_posts', 'exclude_events_category' );
function exclude_events_category( $query ) {
if ( is_single('your-single-post') ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => TribeEvents::TAXONOMY,
'field' => 'slug',
'terms' => array('2012'),
'operator' => 'IN'
)
)
);
}
return $query;
}
Change ‘your-single-post’ to whatever it is and the terms parameter to whatever category you want to include or exclude.I hope that helps!
– Jonah
July 13, 2012 at 1:12 pm #22082Kishore Hari
ParticipantHi all,
I’m tagging onto this post rather than starting a new post since it’s almost the same question.
I also need to display only a particular month in grid view, and I didn’t see that specifically addressed (display only August) in the solution above.
My twist is that I need to display two months of grid view on the same page view.
Thanks,
DamianJuly 16, 2012 at 9:55 am #22155Jonah
ParticipantHi Kishore,
To set the date range for the grid view, you can use the start_date/end_date variables in the pre_get_posts function like so:
add_action( 'pre_get_posts', 'exclude_events_category' );
function exclude_events_category( $query ) {
$current_date = date('j M Y', strtotime('1 month ago'));
$end_date = date('j M Y', strtotime('1 month'));if ( $query->query_vars['eventDisplay'] == 'upcoming' || $query->query_vars['eventDisplay'] == 'past' && $query->query_vars['post_type'] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set('start_date', $current_date);
$query->set('end_date', $end_date);
}
return $query;
}
I hope that helps!
– Jonah
July 16, 2012 at 10:49 am #22156Kishore Hari
ParticipantThanks Jonah! I will try that soon.
Damian (using my client Kishore’s account)July 18, 2012 at 7:24 am #22263Rob
MemberGreat to hear, Damian. Give it a go and let us know if you need anything else from us then.
July 7, 2015 at 6:25 am #977358Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘How to show events for only 1 month and 1 category?’ is closed to new replies.
