首先,如果any
用于post_type
字段不能像问题中那样在数组中给定任何其他值。下面是修改后的参数
$args = [
\'post_type\' => array_values(get_post_types([\'public\' => true])),
\'post_status\' => [\'publish\', \'inherit\'],
\'posts_per_page\' => 10
];
Use posts_where
filter
add_filter(\'posts_where\', \'add_search_mime_types\');
$query = new WP_Query( $args );
remove_filter(\'posts_where\', \'add_search_mime_types\');
function add_search_mime_types($where){
$where .= \' AND post_mime_type IN("application/pdf","") \';
return $where;
}
SQL查询中包含post类型的空字符串,而不是
attachment
.