Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Author Picture › Reply To: Author Picture
April 2, 2020 at 3:35 pm
#26562
Keymaster
Hi,
I assume those are post type results, and you want to display their author image. Well, there is no option for that on the back-end, but it might be possible via a custom code.
Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter( 'asp_results', 'asp_get_author_image_on_cpt', 10, 1 );
function asp_get_author_image_on_cpt($results) {
foreach ( $results as $k => &$r ) {
if ( $r->content_type == 'pagepost' ) {
if ( empty($r->image) ) {
$post_author_id = get_post_field( 'post_author', $r->id );
$img = get_avatar_url($post_author_id);
if ( !empty($img) ) {
$r->image = $img;
}
}
}
}
return $results;
}