Skip to content

Commit

Permalink
Added a 'group_by_taxonomy' optional parameter to wp.getPostTerms.
Browse files Browse the repository at this point in the history
There may be cases where the caller wants a flat list of terms, but other cases where the caller may want the terms grouped by their taxonomy (also consistent with the format of wp.setPostTerms).
  • Loading branch information
maxcutler committed Jan 21, 2012
1 parent bc419c5 commit f31dc8e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion class-wp-xmlrpc-server-ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,17 @@ function wp_getPosts( $args ) {
/**
* Retrieve post terms
*
* The optional $group_by_taxonomy parameter specifies whether
* the returned array should have terms grouped by taxonomy or
* a flat list.
*
* @uses wp_get_object_terms()
* @param array $args Method parameters. Contains:
* - int $blog_id
* - string $username
* - string $password
* - int $post_id
* - bool $group_by_taxonomy optional
* @return array term data
*/
function wp_getPostTerms( $args ) {
Expand All @@ -790,6 +795,7 @@ function wp_getPostTerms( $args ) {
$username = $args[1];
$password = $args[2];
$post_id = (int) $args[3];
$group_by_taxonomy = isset( $args[4] ) ? $args[4] : true;

if ( ! $user = $this->login( $username, $password ) )
return $this->error;
Expand All @@ -815,7 +821,17 @@ function wp_getPostTerms( $args ) {
$struct = array();

foreach ( $terms as $term ) {
$struct[] = $this->prepare_term( $term );
if ( $group_by_taxonomy ) {
$taxonomy = $term->taxonomy;

if ( ! in_array( $taxonomy, $struct ) )
$struct[$taxonomy] = array();

$struct[$taxonomy][] = $this->prepare_term( $term );
}
else {
$struct[] = $this->prepare_term( $term );
}
}

return $struct;
Expand Down

0 comments on commit f31dc8e

Please sign in to comment.