How to show events for only 1 month and 1 category?

Home Forums Calendar Products Events Calendar PRO How to show events for only 1 month and 1 category?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #21960
    Kenny
    Member

    I’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!

    #21975
    Jonah
    Participant

    Hi 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

    #22082
    Kishore Hari
    Participant

    Hi 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,
    Damian

    #22155
    Jonah
    Participant

    Hi 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

    #22156
    Kishore Hari
    Participant

    Thanks Jonah! I will try that soon.
    Damian (using my client Kishore’s account)

    #22263
    Rob
    Member

    Great to hear, Damian. Give it a go and let us know if you need anything else from us then.

    #977358
    Support Droid
    Keymaster

    This 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.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘How to show events for only 1 month and 1 category?’ is closed to new replies.