Home › Forums › Calendar Products › Events Calendar PRO › Custom Search Event Bar using Custom Views Located on Every Page
- This topic has 1 reply, 2 voices, and was last updated 12 years, 3 months ago by
Brook.
-
AuthorPosts
-
January 20, 2014 at 3:03 pm #94893
Adam Listek
ParticipantHello,
I had an incredibly hard time figuring this out, but I finally managed to get everything working. I thought I would help others using what I learned. Please note that this is not easy to do, but it is possible and does work.
What I needed was a search bar on every page, like the Tribe Bar, that could modify the month/list/etc view as neccessary. What I found was that although you can add custom filters and views to the Tribe Bar, I had a very hard time getting to include properly on other pages. In addition, since it is focused on AJAX requests, I couldn’t get it to POST correctly from a standard WordPress page and filter the results on the subsequent result.
Therefore, I decided to code my own form (very simple form to begin with), that would POST the data to the events page and modify the query as necessary.
What I found was that although, the date query modification was easy (just use /events/2013-12 for example and modify the EventDate using the pre_get_posts), this would not filter the events found in each day.
After a lot of searching, I figured out that in the Month view, there is a seperate query using the TribeEventsQuery::getEvents( $args, true ); format in the get_daily_events function in the month template class. This has no filters on it, so therefore there was no way I could figure out how to modify that query (please please add a filter to this, it would have made my life way easier).
In the end, what I found you had to do was create your own view, duplicate the month template class code, change a few things and you would be able to properly do everything you need.
The basic idea is as follows:
1) Create a new view using the Stub Plugin in https://github.com/moderntribe/tribe-events-agenda-view
2) Copy the code from the month.php located underneath the template-classes folder for the plugin.
3) Change classes, make your own, etc.
4) Modify the template files (views) that are included, i.e. content.php, single-day.php, etc to call the static functions from your new class (i.e. My_CustomMonth_Class::is_view_enabled() etc).
5) Change the URL Rewrite for your custom slug:
$newRules[trailingslashit( TribeEvents::instance()->rewriteSlug ) . ‘(\d{4}-\d{2})$’] = ‘index.php?post_type=tribe_events&eventDisplay=customslug&eventDate=’ . $wp_rewrite->preg_index(1);
6) DeQueue the various AJAX Calendar scripts (I reused most of the template code)
7) EnQueue your own and modify as necessary so you could still do AJAX calls if you would like (works fine without)
8) In the Events Settings (WP-Admin), change the default view to your new custom one and leave the slug the same (usually /events/)This has given me full flexibility over filtering and finding the events by the following: date, tag, category, location, search (or anything else custom).
The next thing I am doing is adding autocomplete for the category, tag and location fields. I hope this gives some people ideas on how to do this. I simplified a lot of this as it was very complicated to do but a lot of the challanging parts are outlined above. Good luck!
-Adam Listek
January 21, 2014 at 4:18 pm #95405Brook
ParticipantThank you Adam Listek! This is really helpful. I will make sure to add the appropriate tags to this post so that others can find it even easier.
– Brook
-
AuthorPosts
- The topic ‘Custom Search Event Bar using Custom Views Located on Every Page’ is closed to new replies.
