Home › Forums › Calendar Products › Events Calendar PRO › Target only /events main page in functions
- This topic has 6 replies, 3 voices, and was last updated 9 years, 4 months ago by
Siobhan.
-
AuthorPosts
-
January 9, 2017 at 11:47 pm #1215658
Siobhan
ParticipantHi
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.
January 10, 2017 at 5:19 pm #1216233Siobhan
ParticipantThis reply is private.
January 11, 2017 at 9:54 am #1216741Nico
MemberHi 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,
NicoJanuary 11, 2017 at 3:52 pm #1217033Siobhan
ParticipantI 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.
January 11, 2017 at 6:24 pm #1217111Siobhan
ParticipantNever 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
January 12, 2017 at 1:59 pm #1217687Nico
MemberThanks 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 -
This topic was modified 9 years, 4 months ago by
-
AuthorPosts
- The topic ‘Target only /events main page in functions’ is closed to new replies.
