Using Nickname in custom URL?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Using Nickname in custom URL?

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28248
    chief_martin98
    chief_martin98
    Participant

    Hi support,

    My developer wrote a message to see if you could help.

    ‘I can’t set the URL to use the nickname as that’s not an option in the plugin. If you take a look at this page (scroll to the bottom) you’ll see where it’s set – (see attachment)

    We might need to drop their support an email to ask if it’s possible. I suspect it will need some changes to the plugin code to pull the nickname from the database. Shouldn’t be too difficult, see what they say. In the meantime, I’ve set it to use the Display Name which seems to work, although the URL of the shop page isn’t quite right (though it is loading the correct page).’

    You can see below the results from using the Display Name (1st url) instead of the regular 2nd URL on the website which pulls from the nickname;

    http://XXXXX.co.uk/shops/PhD%20Supplements/
    http://XXXXX.co.uk/shops/phd-supplements/

    Is there any way on the plugin to pull from the nickname or can the plugin include the nickname in the next update? We don’t use ‘Display Name’ or ‘Username’ for the URL.

    Thank you for your assistance

    Attachments:
    You must be logged in to view attached files.
    #28260
    Ernest Marcinko
    Ernest 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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #28392
    chief_martin98
    chief_martin98
    Participant

    Hello, thanks for your reply.

    I have received the following from my developer after passing on your solution.

    “That code looks promising, but at the moment it’s returning the nickname of the currently logged in user (e.g. shops/admindave) instead of the nickname of the user in the result. I think the wp_get_current_user function needs changing to something else, but I’m not sure what’s returned in the results array.

    Might be worth asking them to suggest an amendment.”

    Thanks for your help

    #28407
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Thank you for the feedback, sure, that should not be an issue:

    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( get_post_field( 'post_author', $r->id ), 'nickname', true ), $r->link);
    		}
    	}
    
    	return $results;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.