Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
TEC | Force list view for search results
<?php
// Force list view for search results
// updated to the code provided by a forum user at https://theeventscalendar.com/support/forums/topic/forcing-list-view-for-search-results/#post-1259085
// UNTESTED!
// from https://gist.github.com/cliffordp/a473ccda4308acb9ac66499de5407c9b
add_action( 'wp_footer', function () {
// If tribe-events.js hasn't been setup, do nothing
if ( ! wp_script_is( 'tribe-events-calendar-script' ) ) {
return;
}
print "
<script type='text/javascript'>
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';
}
} );
} );
</script>
";
}, 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment