Created
June 28, 2024 22:42
-
-
Save andrasguseo/169a0fb51031f68a20bccde3e55d3e2b to your computer and use it in GitHub Desktop.
TEC > Show event search results in list view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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