Make WordPress Core

Opened 2 years ago

Closed 20 months ago

Last modified 19 months ago

#23788 closed enhancement (worksforme)

get_posts(array('post_type' => 'any')) Should include custom post types in result

Reported by: keendev Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.5.1
Component: Posts, Post Types Keywords: reporter-feedback
Focuses: Cc:



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 (8)

comment:1 @SergeyBiryukov2 years ago

  • Keywords reporter-feedback added

Are custom post types automatically ignored when using 'any'?

No. Could you provide your post type registration code?

comment:2 @keendev2 years ago

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');


$expired_posts = get_posts(array(
			'post_type' => 'any',
			'meta_query' => array(
				'relation' => 'AND',
					'key' => '_post_expire_time',
					'value' => time(),
					'compare' => '<='
					'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?

comment:3 @keendev2 years ago

  • Keywords dev-feedback added; reporter-feedback removed

comment:4 @keendev2 years ago

Is this related? #18950

Last edited 2 years ago by SergeyBiryukov (previous) (diff)

comment:5 @DrewAPicture2 years 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?

comment:6 @aaronholbrook20 months ago

  • Keywords dev-feedback removed
  • Resolution set to invalid
  • Status changed from new to closed

Just tested on trunk, pulls in your custom post type just fine using 'post_type' => 'any'. Your problem may lie elsewhere, either with improper usage of meta fields or a plugin as Drew suggested.

Unable to reproduce bug, closing as invalid.

comment:7 @ocean9020 months ago

  • Milestone Awaiting Review deleted

comment:8 @SergeyBiryukov19 months ago

  • Resolution changed from invalid to worksforme
Note: See TracTickets for help on using tickets.