This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Using Nickname in custom URL?

#28260
Ernest MarcinkoErnest Marcinko
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;
}