Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#23788 closed enhancement (worksforme)

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

Reported by: keendev's profile keendev Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.5.1
Component: Posts, Post Types Keywords: reporter-feedback
Focuses: 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 (8)

#1 @SergeyBiryukov
12 years ago

  • Keywords reporter-feedback added

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

No. Could you provide your post type registration code?

#2 @keendev
12 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');
	
}

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?

#3 @keendev
12 years ago

  • Keywords dev-feedback added; reporter-feedback removed

#4 @keendev
12 years ago

Is this related? #18950

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

#5 @DrewAPicture
12 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?

#6 @aaronholbrook
12 years 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.

#7 @ocean90
12 years ago

  • Milestone Awaiting Review deleted

#8 @SergeyBiryukov
12 years ago

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