Exclude Category from BOTH Gridview and Listview

Home Forums Calendar Products Events Calendar PRO Exclude Category from BOTH Gridview and Listview

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #20673
    Denis
    Member

    Hi. I need some help. Can’t figure it out how to exclude categories both Gridview and Listview. Looked through this forum, but there is no good solution.

    1. U can exclude it from Grid (functions.php) – https://gist.github.com/2931459
    2. Or u can exclude it from Grid (table.php) – https://gist.github.com/2931458
    3. Also u can exclude it from List (list.php) – https://gist.github.com/2931457

    1 and 2 works fine.
    3 works, BUT it crashes pages and page selection links in listview (same over here – https://theeventscalendar.com/support/forums/topic/removing-one-category-of-events-from-main-event-list-and-calendar/ )

    So I kinda need a solution that excludes it from both type of view.

    #20738
    Denis
    Member

    Eh, I need some support over here…

    #20758
    Jonah
    Participant

    Hey Denis, how about this:

    add_action( 'pre_get_posts', 'exclude_events_category' );
    function exclude_events_category( $query ) {

    if ( $query->query_vars['eventDisplay'] == 'upcoming' || $query->query_vars['eventDisplay'] == 'past' || $query->query_vars['eventDisplay'] == 'month' && $query->query_vars['post_type'] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'tax_query', array(
    array(
    'taxonomy' => TribeEvents::TAXONOMY,
    'field' => 'slug',
    'terms' => array('presentations'),
    'operator' => 'IN'
    )
    )
    );
    }

    return $query;

    }

    #20762
    Denis
    Member

    You mean including only those categories that i need? It’s not a solution for me – client won’t be happy to ask me changing php-file every time he adds a new category.

    #20778
    Jonah
    Participant

    Hey Denis,

    No you change the operator used for the tax_query to ‘NOT IN’ and then have it exclude. You can read more up on tax_query here: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    I hope that helps!

    – Jonah

    #20830
    Denis
    Member

    Thank you! It did help!

    #20832
    Denis
    Member

    But there is 1 more thing…
    Now i have a hidden category for second calendar.
    This category is hidden from both gridview and listview – http://itrackdays.ru/events/
    And u can see it in category’s gridview – – http://itrackdays.ru/events/category/karting-2
    But category’s listview is empty – http://itrackdays.ru/events/category/karting-2/predstoyashhee

    #20963
    Jonah
    Participant

    Hi Denis,

    Last little tip I can provide on this, you’ll need to figure out the rest on your own or hire a developer. Try adding these additional conditions to only filter out the category to be excluded if we are not on a category for the upcoming or past lists:

    add_action( 'pre_get_posts', 'exclude_events_category' );
    function exclude_events_category( $query ) {

    if ( $query->query_vars['eventDisplay'] == 'upcoming' && !is_tax(TribeEvents::TAXONOMY) || $query->query_vars['eventDisplay'] == 'past' && !is_tax(TribeEvents::TAXONOMY) || $query->query_vars['eventDisplay'] == 'month' && $query->query_vars['post_type'] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'tax_query', array(
    array(
    'taxonomy' => TribeEvents::TAXONOMY,
    'field' => 'slug',
    'terms' => array('2012'),
    'operator' => 'NOT IN'
    )
    )
    );
    }

    return $query;

    }

    I hope that helps!

    – Jonah

    #977147
    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 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Exclude Category from BOTH Gridview and Listview’ is closed to new replies.