admin管理员组文章数量:1122832
I have a search page with a custom filter that I use to only retrieve posts of 'attachment' post_type. Here is a greatly shortened version:
function MySearchFilter($query) {
if( ($query->is_search) {
$query->set('post_type', 'attachment');
}
}
add_filter('pre_get_posts','MySearchFilter');
That works fine.
I thought I could use the same technique to limit posts by mime type like so:
$query->set('post_mime_type', 'application/pdf' );
Or
$query->set('post_mime_type', 'image/jpeg');
And so on...
These do not seem to work. And all the examples I have found seem to refer to creating a -new- query, not modifying the existing query as I hope to do.
It's as if WordPress simply ignores this property.
Is this possible? If so, how?
本文标签: pre get postsCan I filter existing search query using pregetposts for postmimetype
版权声明:本文标题:pre get posts - Can I filter existing search query using pre_get_posts for post_mime_type? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309443a1934024.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论