Target only /events main page in functions

Home Forums Calendar Products Events Calendar PRO Target only /events main page in functions

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1215658
    Siobhan
    Participant

    Hi

    I need to have a page with a filter bar that only displays certain – multiple – categories. For example I would like a calendar that shows primary, secondary, early-years events. I can do this via shortcode but then the Filter Bar isn’t compatible with the shortcode (I wish I’d known that before purchasing, but hey)

    In this case, I’d like to use the main page ‘/events’ to show certain categories with the filter bar. I think the easiest way would be to excluse the 1 or 2 categories I don’t want. I have the code from another post in the forum but my issue is that I don’t know how to target the main events page in functions.php as it doesn’t seem to have an ID. I need to target that specific List otherwise is_single() excludes those categories from every page I am using the shortcode on.

    Can you help me to target that specific page? The code I have is below. My PHP knowledge is not great so please let me know if there are any major errors as well.

    add_action( 'pre_get_posts', 'tribe_exclude_events_category_month_list' );
    function tribe_exclude_events_category_month_list( $query ) {
     
        if ( isset( $query->query_vars['eventDisplay'] ) && ! is_singular( 'tribe_events' )  ) {
     
            if ( $query->query_vars['eventDisplay'] == 'list' && ! is_tax( Tribe__Events__Main::TAXONOMY ) || $query->query_vars['eventDisplay'] == 'photo' && $query->query_vars['post_type'] == Tribe__Events__Main::POSTTYPE && ! is_tax( Tribe__Events__Main::TAXONOMY ) && empty( $query->query_vars['suppress_filters'] ) ) {
     
                $query->set( 'tax_query', array(
     
                    array(
                        'taxonomy' => Tribe__Events__Main::TAXONOMY,
                        'field'    => 'slug',
                        'terms'    => array( 'alum-events' ),
                        'operator' => 'NOT IN'
                    )
                ) );
            }
     
        }
     
        return $query;
    }
    • This topic was modified 9 years, 4 months ago by Siobhan.
    #1216233
    Siobhan
    Participant

    This reply is private.

    #1216741
    Nico
    Member

    Hi there Siobhan,

    Thanks for getting in touch with us and sorry to hear about the issue setting up the site πŸ™

    To customize the script you can add view conditionals such as: tribe_is_month(), tribe_is_day(), tribe_is_list_view(), etc or account for other situations like: tribe_is_event_category(), tribe_is_event_venue() or tribe_is_event_organizer(). It all depends on what you are looking for!

    If you just want to amend the previous snippet try replacing: && ! is_singular( 'tribe_events' ) with && ! is_singular( ) and that should de the trick for you.

    Please let me know if this helps,
    Best,
    Nico

    #1217033
    Siobhan
    Participant

    I think maybe I wasn’t clear? I am using the shortcode to display different categories on multiple single pages. However on the MAIN Events Cal page I want to hide a few categories.

    If I target !is_singular() won’t it hide those categories from all the pages using the shortcode ?

    The others won’t work either as I am using list view for all of the instances

    I just need to target only /events page (the HR calendar) and no other to remove e.g. alumni and celebration events. Thanks.

    #1217111
    Siobhan
    Participant

    Never mind, removing ‘tribe_events’ from is_singular() worked – clearly I need to work on my PHP knowledge.

    Thanks a lot.

    • This reply was modified 9 years, 4 months ago by Siobhan. Reason: typo
    #1217687
    Nico
    Member

    Thanks for following up Siobhan πŸ™‚

    Glad the simple workaround of removing the post type from is_singular worked for you!

    This is a good article about customizing the WordPress query β†’ http://www.billerickson.net/customize-the-wordpress-query/

    And here one for understanding WordPress filters β†’ https://pippinsplugins.com/a-quick-introduction-to-using-filters/

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Target only /events main page in functions’ is closed to new replies.