Using Nickname in custom URL?
Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Using Nickname in custom URL?
- This topic has 3 replies, 2 voices, and was last updated 6 years ago by
Ernest Marcinko.
-
AuthorPosts
-
July 5, 2020 at 1:05 am #28248
chief_martin98
ParticipantHi 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
July 6, 2020 at 1:05 pm #28260Ernest Marcinko
KeymasterHi,
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; }July 11, 2020 at 1:59 pm #28392chief_martin98
ParticipantHello, 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
July 13, 2020 at 11:37 am #28407Ernest Marcinko
KeymasterHi,
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; } -
AuthorPosts
- You must be logged in to reply to this topic.