Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active July 10, 2025 07:29
Show Gist options
  • Save Crocoblock/57708a1ce484bee9ba794a4316626005 to your computer and use it in GitHub Desktop.
Save Crocoblock/57708a1ce484bee9ba794a4316626005 to your computer and use it in GitHub Desktop.
JetSearch / Search in Media
<?php
add_filter( 'jet-search/tools/get-post-types', function( $post_types ) {
$post_types['attachment'] = 'Media';
return $post_types;
} );
add_filter( 'jet-search/ajax-search/query-args', function( $query ) {
if ( in_array( 'attachment', $query['post_type'] ) ){
$query['post_status'] = [ 'any' ];
}
return $query;
} );
add_filter( 'jet-search/ajax-search/thumbnail-html', function( $html, $post, $data ) {
$size = ! empty( $data['thumbnail_size'] ) ? $data['thumbnail_size'] : 'thumbnail';
$img = $post->post_type === 'attachment' ? wp_get_attachment_image( $post->ID, $size ) : '%s';
$html = '<div class="jet-ajax-search__item-thumbnail">' . $img . '</div>';
return $html;
}, 10, 3 );
@Crocoblock
Copy link
Author

Works with JetSearch 3.5.11+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment