WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#13150 closed defect (bug) (worksforme)

get_posts( post_type=x & custom_tax=y ) ignores the custom post type

Reported by: bobsoap Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords: custom post type, custom taxonomy
Focuses: Cc:

Description

When calling get_posts with both a custom post type and a custom taxonomy, all posts that are attached to that taxonomy are returned, regardless of the post type.

Example:

//the taxonomy
register_taxonomy(
	'genre',
	array('movies','genre_descriptions'), //attach to 2 objects
	array(	'hierarchical' => false,
		'label' => 'Genre',
		'show_ui' => true,
		'query_var' => true,
		'rewrite' => array('slug' => ''),
		'singular_label' => 'Genre'
		)
	);

//trying to get only the genre descriptions for a genre
get_posts('post_type=genre_descriptions&genre=my-genre&status=publish&posts_per_page=-1')

//returns all posts with the genre "my-genre", even when they are not a "genre_descriptions" post type

WP 3.0 beta 1

Change History (2)

comment:1 @michaelh5 years ago

Maybe it is this 'status=publish'

This works for me

<?php 
$args=array(
  'post_type' => 'book',
  'writer' => 'John',
  'post_status' => 'publish',
  'posts_per_page' => -1
    );
$return=get_posts($args);
echo "<pre>"; print_r($return); echo "</pre>";
?>

If that doesn't resolve it, also there was ticket:13020 last week -- have you updated to the latest nightly?

comment:2 @michaelh5 years ago

  • Milestone 3.0 deleted
  • Priority changed from high to normal
  • Resolution set to worksforme
  • Severity changed from major to normal
  • Status changed from new to closed

Closing as worksforme. Please reopen upon new evidence.

Note: See TracTickets for help on using tickets.