Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#10934 closed defect (bug) (worksforme)

get_posts with a custom post_type and a custom taxonomy returns empty

Reported by: jorbin's profile jorbin Owned by: filosofo's profile filosofo
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords:
Focuses: Cc:

Description

get_posts returns empty when using both a custom post_type and a custom taxonomy.

Change History (3)

#1 @pento
15 years ago

  • Cc pento added
  • Version changed from 2.9 to 3.0

Test case:

register_post_type('custom_type', array('exclude_from_search' => false));
register_taxonomy('custom_category', array('custom_type'), array('hierarchical' => false, 'label' => __('Category', 'series')));

$catid = wp_insert_term('Test Category', 'custom_category', array('slug' => 'test-category'));

$post = array(
	'comment_status' => 'closed',
	'ping_status' => 'closed',
	'post_status' => 'publish',
	'post_author' => 1,
	'post_content' => 'test content',
	'post_name' => 'test',
	'post_title' => 'Test Post',
	'post_type' => 'custom_type');
$postid = wp_insert_post($post);

wp_set_object_terms($postid, $catid, 'custom_category', true);

$single = get_post($postid);
var_dump($single);

$search = get_posts('post_type=custom_type&custom_category=test-category');
var_dump($search);

#2 @pento
15 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

On further testing, it appears to be fixed in 2.9.1 and 3.0.

jorbin: check that you are using 'exclude_from_search' => false, otherwise the post type will always be excluded from a get_posts() search.

#3 @filosofo
15 years ago

  • Milestone Unassigned deleted
Note: See TracTickets for help on using tickets.