Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created June 28, 2024 22:42
Show Gist options
  • Save andrasguseo/169a0fb51031f68a20bccde3e55d3e2b to your computer and use it in GitHub Desktop.
Save andrasguseo/169a0fb51031f68a20bccde3e55d3e2b to your computer and use it in GitHub Desktop.
TEC > Show event search results in list view
<?php
add_filter( 'tribe_events_views_v2_rest_params', 'tec_redirect_search_to_list_view', 10, 2 );
function tec_redirect_search_to_list_view( $params, $request ) {
$ref = $_SERVER['HTTP_REFERER'];
// Are you coming from the list view?
$coming_from_list = str_contains( $ref, '/list/' );
if (
// If there is a search
// AND you're NOT coming from list view
! empty( $params['tribe-bar-search'] )
&& ! $coming_from_list
) {
// then redirect to list view
$params['eventDisplay'] = 'list';
} else {
// Otherwise don't redirect
// AND remove search
unset( $params['tribe-bar-search'] );
}
return $params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment