A couple of years too late, but you can use the get_post_types() function with the operator
parameter set to not
. This way, you will receive an array of all post types except the one(s) you set in the args
parameter of the function, which you can then use to define the post_type
in your query:
$args = array(
's' => $s,
'posts_per_page' => -1,
'post_type' => get_post_types(array('name' => 'klanten', 'public' => false), 'names', 'not')
);
$query = new WP_Query( $args );
However, you might want to var_dump()
the result of the function first, since it will return other hidden post types you might not be interested in (like 'attachments' or others defined by plugins). This is the reason why I added 'public' => false
, which will make sure that I only receive public post types. This removes most of the undesired post types, but you should still check ('attachments' is not removed by this).
Another shortcoming of this method is that you can only remove one post type. A workaround for that would be to get all post types and then remove the ones you don't want from the array using the method described here, but that seems like too much code, so in that case you might be better off just setting all the post types you want instead of the ones you don't.