This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Media Search Results

#38121
Ernest MarcinkoErnest Marcinko
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;
}