Last active
March 22, 2023 04:19
-
-
Save cryptexvinci/a159a8f394e797e0ee16961c4e9e83b2 to your computer and use it in GitHub Desktop.
Get Ultimate member Search Term or keyword
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 | |
/** | |
* Gets the search term from the member directory search query. | |
* | |
* @return void | |
*/ | |
function um_member_directory_search_term() { | |
// Only execute on the members page. | |
if ( ! um_is_core_page( 'members' ) ) { | |
return; | |
} | |
// Get the URL of the current request. | |
$search_url = parse_url( $_SERVER['REQUEST_URI'] ); | |
// Check if the query string contains search parameters. | |
if ( isset( $search_url['query'] ) ) { | |
// Split the query string into an array. | |
$array = explode( '&', $search_url['query'] ); | |
// Create an array of search parameters. | |
$search_array = array(); | |
foreach ( $array as $value ) { | |
if ( strpos( $value, 'search_' ) === 0 ) { | |
$search_array[] = $value; | |
} | |
} | |
// Get the first search parameter. | |
$search_term_array = explode( '=', $search_array[0] ); | |
// Get the search term and sanitize it. | |
$search_term = sanitize_text_field( $search_term_array[1] ); | |
// Echo the search term. | |
return $search_term; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment