Forcing list view for search results

Home Forums Calendar Products Events Calendar PRO Forcing list view for search results

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1255442
    Meredith
    Participant

    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!

    • This topic was modified 7 years, 1 month ago by Meredith. Reason: the "code" tags were messing things up so I removed them
    • This topic was modified 7 years ago by Cliff.
    #1256113
    Hunter
    Moderator

    Hey 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!

    #1259085
    Meredith
    Participant

    Thanks, 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';
            }
    
        } );
    } );
    #1259763
    Hunter
    Moderator

    Thank 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!

    #1271447
    Cliff
    Member

    For others’ reference, here’s the full code snippet, assuming I understood Meredith’s modifications (thanks for sharing):

    https://gist.github.com/cliffordp/a473ccda4308acb9ac66499de5407c9b

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Forcing list view for search results’ is closed to new replies.