Last active
July 10, 2025 07:29
-
-
Save Crocoblock/57708a1ce484bee9ba794a4316626005 to your computer and use it in GitHub Desktop.
JetSearch / Search in Media
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works with JetSearch 3.5.11+