In WP 3.1, it appears that setting 'exclude_from_search' = TRUE
for a custom post type excludes the post type not just from searches on the front-end, but also from any post query using 'post_type' = 'all
'.
I can imagine plenty of scenarios where a plug-in developer would want to access ALL post types, even those excluded from front-end searches. Is this a bug, or is it just poorly documented?
Backstory:
I have a custom post type using a custom "Post Expiration Date" field. In an attempt to automatically un-publish expired custom posts, I created a Content Expiration plugin which uses wp_schedule_event() to periodically unpublish posts where "Post Expiration Date" < Today. It worked great as long as I specified my custom post type, but it stopped working when I tried to make it more generic by setting 'post_type' = 'all'
in the WP_Query arguments. Turns out the problem was the 'exclude_from_search' argument for the custom post type. Here's the pertinent code in the WP_Query class:
$exclude_post_types = '';
$in_search_post_types = get_post_types( array('exclude_from_search' => false) );
if ( ! empty( $in_search_post_types ) )
$exclude_post_types .= $wpdb->prepare(" AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')");
if ( 'any' == $post_type ) {
$where .= $exclude_post_types;
}