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

Reply To: Search for media and exclude search from media in custom post type

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Search for media and exclude search from media in custom post type Reply To: Search for media and exclude search from media in custom post type

#36314
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Well, the first issue might be possible to resolve via a custom code, but I am not entirely sure though. If the post parent ID is not set via the custom field input, then it is not going to work.
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_remove_attachments_where_post_type', 10, 1);
function asp_custom_footer_script( $results ) {
	$excluded = array(
		'post_type_name1',
		'post_type_name2',
	);

	foreach ( $results as $k => $r ) {
		if ( isset($r->post_type) && $r->post_type == 'attachment' ) {
			$parent_id = wp_get_post_parent_id($r->id);
			if ( $parent_id != 0 ) {
				if ( in_array(get_post_type($parent_id), $excluded) ) {
					unset($results[$k]);
				}
			}
		}
	}
	
	return $results;
}

You need to change the $excluded variable for the post type names you want to exclude the attachment results for.

The second issue is kind of intentional, it is to limit the number of iterations to 10x on the more results feature. It can be changed via a custom code as well:

add_filter( 'asp_query_args', 'asp_change_remaining_limit_mod', 10, 2 );
function asp_change_remaining_limit_mod( $args, $id ) { 
  
  $args['_remaining_limit_mod'] = 9999;
  
  return $args;
}