Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Index specific directory with attachments › Reply To: Index specific directory with attachments
April 8, 2025 at 10:51 am
#53623
Keymaster
Hi Erika,
Well, it might be possible with a custom code snippet, but I’m not a 100% sure. In the code below, change the $folder variable to the folder name where of where you want the attachments to be indexed from:
add_filter(
'asp_index_post',
function ( WP_Post $post ) {
$folder = 'included_folder_name'; // Change this to the attachment folder to include
if ( $post->post_type !== 'attachment' ) {
return $post;
}
if ( strpos($post->guid, $folder) !== false ) {
return $post;
}
return null;
}
);
After adding this code, please make a new index.
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.