Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Using Nickname in custom URL? › Reply To: Using Nickname in custom URL?
July 6, 2020 at 1:05 pm
#28260
Keymaster
Hi,
I recommend using the asp_results custom hook, that allows programatically modifying the results URL.
I would resolve it by using a new variable in the results {USER_NICKNAME} and use this custom code to make the actual replacement:
add_filter( 'asp_results', 'asp_custom_link_results', 10, 1 );
function asp_custom_link_results( $results ) {
// Parse through each result item
foreach ($results as $k=>&$r) {
if ( $r->content_type == 'user' ) {
$r->link = str_replace('{USER_NICKNAME}', get_user_meta( wp_get_current_user()->ID, 'nickname', true ), $r->link);
}
}
return $results;
}