Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Media Search Results › Reply To: Media Search Results
June 16, 2022 at 3:12 pm
#38064
Keymaster
Hi,
I think both should be possible via a custom code snippet.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter( 'asp_results', 'asp_attachment_title_field', 10, 1 );
function asp_attachment_content_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;
}
This should change the titles to the parent post title, and remove items from the results where the post type is not “candidate”