Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#13109 closed enhancement (fixed)

get_taxonomies should filter object_type

Reported by: michaelh's profile michaelh Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:

Description

get_taxonomies should filter on the object_type to allow retrieving all taxonomies for a particular post_type. Example:

$args=array(
  'object_type' => array('book','movie')
);
$output = 'objects'; 
$taxonomies=get_taxonomies($args,$output);

Note: get_object_taxonomies('book'); does return the taxonomy names related to an object_type / post_type

Attachments (3)

13109.diff (1.1 KB) - added by scribu 15 years ago.
wp_filter_object_list.diff (593 bytes) - added by scribu 15 years ago.
wp_filter_object_list.2.diff (700 bytes) - added by scribu 15 years ago.
added brackets

Download all attachments as: .zip

Change History (16)

#1 @scribu
15 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0

I often found it frustrating that get_object_taxonomies() only returned the taxonomy names.

Patch adds an $output parameter to get_object_taxonomies().

#2 @scribu
15 years ago

To further filter the taxonomy objects you could do something like this:

`
$taxonomies = get_object_taxonomies('post', 'objects');

$taxonomies = wp_filter_object_list($taxonomies, array('_builtin' => false));
`

#3 @michaelh
15 years ago

  • Keywords tested added

Thought you might change wp_filter_object_list to do that ;)

Okay tested that with both 'names' and 'objects' and it works.

Don't know why I had to apply that patch manually.

Thanks scribu.

@scribu
15 years ago

#4 @scribu
15 years ago

  • Keywords commit added

#5 @nacin
15 years ago

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

(In [14479]) Allow get_object_taxonomies to return taxonomy objects. props scribu, fixes #13109.

#6 @nacin
15 years ago

(In [14480]) Small fix to r14479. see #13109.

#7 @nacin
15 years ago

Had to make a small change, at least one place in trunk checked for the [0] key. If you want to re-patch core to assume that the key is a name, instead of numeric, then feel free to re-open.

#8 @scribu
15 years ago

Yeah, same as with #13246

#9 @scribu
15 years ago

  • Keywords tested removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

We should have consistent behaviour between get_object_taxonomies() and get_taxonomies().

wp_filter_object_list.diff makes it so that get_taxonomies(, 'names') also returns a numeric array.

#10 @nacin
15 years ago

Missing some brackets there.

I did a quick scan and couldn't find any other times we use a key from get_post_stati, get_taxonomies, or get_post_types.

#11 @scribu
15 years ago

Even so, it doesn't make much sense to return something like this:

`
array(

[category] => category,
[post_tag] => post_tag,
...

)
`

I meant get_taxonomies('', 'names')

#12 @nacin
15 years ago

Hah, brackets are missing in the patch.

And I was simply confirming that no other places in core needed to be modified after this change.

@scribu
15 years ago

added brackets

#13 @nacin
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [14495]) Standardize returned array keys when output = 'names'. Return numeric keys. Standardizes get_object_taxonomies with get_taxonomies, get_post_types, and get_post_stati. props scribu. fixes #13109.

Note: See TracTickets for help on using tickets.