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

Reply To: PDF search results

#40768
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

1.Okay, I have logged in to check and made a tiny modification. Can you please test if this changed anything.

For reference the new code is:

add_filter( 'asp_results', 'asp_attachment_parent_in_category', 10, 1 );
function asp_attachment_parent_in_category( $results ) {
  // Category IDs
  $categories = array(28);
  
  foreach ($results as $k=>&$r) {
	if ( isset($r->post_type) && $r->post_type == 'attachment' ) {
		$parent_id = wp_get_post_parent_id( $r->id );
		if ( !is_wp_error($parent_id) && !empty($parent_id) ) {
			if ( $parent_id == 0 || !in_category($categories, $parent_id) ) {
				unset($results[$k]);
			}			
		} else {
			unset($results[$k]);
		}
	}
  } 
  return $results;
}