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