您可以通过一个简单的查询很容易地做到这一点:
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE meta_key = \'_wp_attachment_metadata\' AND meta_value LIKE \'%carousel%\'");
foreach($results as $result){
//$result->post_id will give you the original attachment post
}