Opened 2 months ago
Last modified 5 weeks ago
#23788 new enhancement
get_posts(array('post_type' => 'any')) Should include custom post types in result
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Post Types | Version: | 3.5.1 |
| Severity: | minor | Keywords: | dev-feedback reporter-feedback |
| Cc: |
Description
Hi,
I have a post type called with the id of 'career'. When I use post_type => 'any' I don't get results from this post type even though it is set to public. Are custom post types automatically ignored when using 'any'?
When replacing 'any' with 'career' it works fine.
Change History (5)
comment:1
SergeyBiryukov — 2 months ago
- Keywords reporter-feedback added
function career_manager() {
$labels = array(
'name' => _x( 'Careers', 'post type general name' ),
'singular_name' => _x( 'Career', 'post type singular name' ),
'add_new' => _x( 'Add New', 'brand' ),
'add_new_item' => __( 'Add New Career' ),
'edit_item' => __( 'Edit Career' ),
'new_item' => __( 'New Career' ),
'all_items' => __( 'Career' ),
'view_item' => __( 'View Careers' ),
'search_items' => __( 'Search Careers' ),
'not_found' => __( 'No careers found' ),
'not_found_in_trash' => __( 'No careers found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Careers'
);
$args = array(
'labels' => $labels,
'description' => 'Career Manager',
'public' => true,
'show_ui' => true,
'menu_position' => 13,
'supports' => array( 'title', 'editor'),
'has_archive' => true,
'register_meta_box_cb' => 'register_careers_metaboxes'
);
register_post_type('career', $args);
}
add_action( 'init', 'career_manager' );
function register_careers_metaboxes() {
add_meta_box('career_details', 'Details', 'career_details_meta_box', 'career', 'side');
}
Referencing:
$expired_posts = get_posts(array( 'post_type' => 'any', 'meta_query' => array( 'relation' => 'AND', array( 'key' => '_post_expire_time', 'value' => time(), 'compare' => '<=' ), array( 'key' => '_post_expire_time', 'value' => '', 'compare' => '!=' ) ) ));
Some more info: My posts were expired on the 25th feb 2013. It never picked up these expired careers. The minute i changed it to post_type => 'career', it found the results. Maybe there is something deeper happening here?
Is this related? #18950
comment:5
DrewAPicture — 2 months ago
- Keywords reporter-feedback added
I can't reproduce this with your code in Twenty Twelve on 3.5.1.
I created a couple of test careers and with the _post_expire_time meta keys of both past timestamps and empty. get_posts() yielded exactly what I expected it to with 'post_type' => 'any' set.
Is it possible you have a plugin or function that's messing with the global query?

No. Could you provide your post type registration code?