我正在从事一个项目,该项目需要使用给定的分类法slug对搜索附件(在本例中,category
=javascript
). 我正在使用get_posts()
具有tax_query
设定要实现这一点,但它正在返回零收益。
传递给get\\u posts()的数组如下:
array(8) {
["tax_query"]=>
array(1) {
[0]=>
array(3) {
["taxonomy"]=>
string(8) "category"
["field"]=>
string(4) "slug"
["term"]=>
array(1) {
[0]=>
string(10) "javascript"
}
}
}
["numberposts"]=>
int(-1)
["orderby"]=>
string(10) "menu_order"
["order"]=>
string(3) "ASC"
["post_status"]=>
string(7) "inherit" // \'any\' also tried
["post_type"]=>
string(10) "attachment"
["post_mime_type"]=>
string(34) "application,video,text,audio,image"
["post_parent"]=>
string(0) ""
}
类别中有一个图像
JavaScript
(其中
javascript
但它不会被退回。
此外,在不太可能的情况下,通过使用Media Categories.
EDIT: post_status=>inherit
和post_status=>any
都试过了,结果没有改变。
EDIT 2: 创建新的WP_Query
对象,省去meta_query
创建有效的SQL,但包括meta_query
添加以下内容:AND 0 = 1
, 这显然使整个查询不返回任何内容。生成的整个SQL如下所示:
SELECT SQL_CALC_FOUND_ROWS cms_posts.ID
FROM cms_posts
WHERE 1=1
AND 0 = 1
AND (
cms_posts.post_mime_type
LIKE \'application/%\'
OR cms_posts.post_mime_type
LIKE \'video/%\'
OR cms_posts.post_mime_type
LIKE \'text/%\'
OR cms_posts.post_mime_type
LIKE \'audio/%\'
OR cms_posts.post_mime_type
LIKE \'image/%\')
AND cms_posts.post_type = \'attachment\'
AND (cms_posts.post_status <> \'trash\'
AND cms_posts.post_status <> \'auto-draft\'
AND cms_posts.post_status <> \'spam\')
GROUP BY cms_posts.ID
ORDER BY cms_posts.menu_order
ASC LIMIT 0, 10