hi @fff654
Yes you can do this with some custom PHP code. I have tested this and it works by doing a search for attachment names:
/**
* Override attachments for a FooGallery based on a search by attachment filename.
*
* example :
*
* [foogallery id="123" attachment_search="my_string-"]
*/
add_filter( 'foogallery_render_template_argument_overrides', function( $foogallery, $args ) {
if ( empty( $args['attachment_search'] ) ) {
return $foogallery;
}
$search = sanitize_file_name( wp_unslash( $args['attachment_search'] ) );
if ( '' === $search ) {
return $foogallery;
}
global $wpdb;
// _wp_attached_file values are usually like "2026/03/my_string-image.jpg"
$ids = get_posts( array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_type' => 'image',
'fields' => 'ids',
'numberposts' => -1,
'orderby' => 'date',
'order' => 'ASC',
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'meta_query' => array(
array(
'key' => '_wp_attached_file',
'value' => $search,
'compare' => 'LIKE',
)
),
) );
$foogallery->attachment_ids = array_map( 'intval', $ids );
return $foogallery;
}, 10, 2 );