基本上,解决方案是包括除图像以外的所有MIME。WordPress有一个漂亮的小功能,它保存了所有被接受的mime类型,称为get_allowed_mime_types()
(名称巧妙)返回一个MIME数组()。我们所需要做的就是获取返回的数组和查询中不需要的mime类型数组之间的差异:
$unsupported_mimes = array( \'image/jpeg\', \'image/gif\', \'image/png\', \'image/bmp\', \'image/tiff\', \'image/x-icon\' );
$all_mimes = get_allowed_mime_types();
$accepted_mimes = array_diff( $all_mimes, $unsupported_mimes );
$attachment_query = new WP_Query( array(
\'post_type\' => \'attachment\',
\'post_status\' => \'inherit\',
\'post_mime_type\' => $accepted_mimes,
\'posts_per_page\' => 20,
) );