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

Reply To: How to exclude certain media files from the search?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support How to exclude certain media files from the search? Reply To: How to exclude certain media files from the search?

#43072
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Thank you very much for your kind words and for the details it helps me a lot!

I believe the best way to get around this is by using this option to exlude media files by their IDs.

Unfortuntely there is no option to include only specific media files, but it should be still doable via using a small custom code snippet:

add_filter("asp_query_args", "asp_query_args_change", 10, 2);
function asp_query_args_change($args, $search_id) {
	$include_ids = array(1, 2, 3); // Media file IDS to include
	
	// No change below
	$ids = implode(', ', $include_ids);
	$args['attachment_query']['where'] = "AND $wpdb->posts.ID IN($ids)";
	return $args;
}

In this code you only need to change the $include_ids variable and add the meida file IDs which you want to see in the results list. Try adding this code via the Code Snippets plugin or 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.