Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Media Search Results › Reply To: Media Search Results
June 21, 2022 at 1:35 pm
#38121
Keymaster
Thank you!
It was luckily a minor error in the code, that I didn’t notice, with some testing I was able to see it right away. I placed the corrected function there, for future reference this is the correct code:
add_filter( 'asp_results', 'asp_attachment_title_field', 10, 1 );
function asp_attachment_title_field( $results ) {
foreach ($results as $k=>&$r) {
if ( $r->content_type == 'attachment' ) {
$parent_id = wp_get_post_parent_id( $r->id );
if ( !is_wp_error($parent_id) && !empty($parent_id) ) {
$parent = get_post( $parent_id );
if ( $parent->post_type == 'candidate' ) {
// Change the title
$r->title = get_the_title( $parent);
} else {
unset($results[$k]);
}
}
}
}
return $results;
}