Searching Image EXIF metadata

Indexing image metadata with Ajax Search Pro

Prerequesites

The snippet below will hook into the index process and read the file EXIF metadata to append to the indexed image files. It works for all image mime types.

What is this, and where do I put this custom code?

add_filter( 'asp_index_file_custom_parse', function ( $contents, $the_post ) {
	if ( wp_attachment_is_image($the_post) ) {
		$file_path = get_attached_file($the_post->ID);
		$data = wp_read_image_metadata($file_path);
		if ( is_array($data) ) {
			$data = array_filter($data, fn($s)=>!empty($s));
			$contents = implode(', ', $data);
		}
	}

	return $contents;
}, 10, 2);

Last updated