Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Image – avatar in search results
This topic contains 4 replies, has 2 voices, and was last updated by sabbella 4 years, 7 months ago.
- AuthorPosts
- May 1, 2019 at 1:43 pm #22416
Hello Ernest,
Excuseme for writing again for the same topic I opened before; I can’t find a solution for it.
I’m still trying to display the wp_get_attachment_image from the users in my theme default search results page in order to display it next to their usernames as avatar.
The code I have can display correctly $args and $avatar in the header of the page, AND $args in the users list search results, but not $avatar in the users list search results.
I think it coul be because it can’t get correctly $user->ID in the user list search results, so I would like to ask you the way Ajax Search Pro plugin get users in the search results page in order to modify my code.
This is what I have now:
function my_user_avatar_filter( $avatar, $id_or_email, $args) {
$id_or_email = get_userdata($id_or_email);
$attachment_id = get_user_meta( $id_or_email->ID, ‘foto’, true );
if (get_user_meta( $id_or_email->ID, ‘foto’, true )){
//$avatar_url = wp_get_attachment_url( $attachment_id, $size );
//$avatar = ““;
$size= array(’80’,’80’);
$avatar = wp_get_attachment_image($attachment_id, $size);
echo $avatar;
} else {
$args=”
“;
echo $args;
}
}
add_filter( ‘get_avatar’, ‘my_user_avatar_filter’, 10, 3 );Thank you,
May 2, 2019 at 9:12 am #22429Hi,
Well, this custom code looks okay to me, it is very hard to tell where the problem might be. It is very much possible, that the ‘get_avatar’ hook might not be executed whatsoever within the results page context. Maybe directly editing the theme file would be a better idea instead of using a custom hook, I am not sure.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 2, 2019 at 9:23 am #22432Thank you Ernes, I’ll try that way.
May 2, 2019 at 2:47 pm #22448Hi Ernest, would it be possible to display de images using the advanced title field {foto} in some way ? {foto} just displays the image ID
Thank you,
May 2, 2019 at 5:35 pm #22449Hello Ernest, I found a way of doing it,
Thank you 🙂
- AuthorPosts
The topic ‘Image – avatar in search results’ is closed to new replies.