Home › Forums › Calendar Products › Events Calendar PRO › Forcing list view for search results
- This topic has 5 replies, 4 voices, and was last updated 7 years ago by Cliff.
-
AuthorPosts
-
March 16, 2017 at 12:15 pm #1255442MeredithParticipant
We’d like to force search results to switch from month view to list view. I did find another post about this, but it just links to a page that describes forcing list view for mobile users (which I’m already doing via better methods).
I can think of two ways to solve this but for each of them I need one piece of information from you!
1. Hook into the “submit search” js. I just need you to tell me the hook. For example, on another site I want to change my page title when navigating from week to week or month to month. My javascript for that starts with $(tribe_ev.events).on(‘tribe_ev_ajaxStart’, function(e) {… What would I use for search submit? tribe_ev_ajaxSearch or something? I don’t want to guess. If I know that, I can then trigger a page redirect to /events/list/ while grabbing the search term.
2. Expand upon the solution for mobile users offered here, but instead of wp_is_mobile(), I would need to know how TEC knows, in PHP, that a search has been performed… tribe_is_search() or something? Again, I don’t want to guess. Can you tell me that?
Of course, if you have any other suggestions, I’m all ears! But if you can give me those two hooks (or direct me to a comprehensive API where I can look these things up myself), then I can craft my solution.
Thanks!
March 17, 2017 at 3:34 pm #1256113HunterModeratorHey Meredith 🙂
Welcome back and I hope your weekend is off to a great start. We’re obviously limited in this situation as stated in our What support is provided for license holders? Knowledgebase article, but you sound prepared enough to tackle the challenge.
Check out this bit of code and let me know if it helps. I believe it should do the trick. Have a pleasant rest of your Friday and thanks for choosing PRO!
March 23, 2017 at 2:23 pm #1259085MeredithParticipantThanks, Hunter. That totally helped. The code you gave me didn’t work exactly, because it also fired if the user just clicked the “next month” link at the bottom of the grid, but I fixed it by adding a regex. Here’s my final working code:
jQuery( document ).ready( function( $ ) { if ( 'object' !== typeof tribe_ev ) return; var existingSearch = tribe_ev.state.url_params; $( tribe_ev.events ).on( 'tribe_ev_collectParams', function() { var issearch = tribe_ev.state.url_params.match(/tribe\-bar\-search/g); if(issearch) { window.location = '/events/?' + tribe_ev.state.url_params + '&eventDisplay=list'; } } ); } );
March 24, 2017 at 12:22 pm #1259763HunterModeratorThank you for letting me know you’ve got things figured out and also for sharing your solution for others to learn from. Feel free to create a new thread if you have any more questions or comments and have a pleasant weekend ahead. Cheers!
April 18, 2017 at 8:42 pm #1271447CliffMemberFor others’ reference, here’s the full code snippet, assuming I understood Meredith’s modifications (thanks for sharing):
https://gist.github.com/cliffordp/a473ccda4308acb9ac66499de5407c9b
-
AuthorPosts
- The topic ‘Forcing list view for search results’ is closed to new replies.