Opened 9 years ago
Closed 7 years ago
#35925 closed enhancement (fixed)
Filter for wp_get_object_terms() arguments
Reported by: | enrico.sorcinelli | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | Taxonomy | Keywords: | has-patch has-unit-tests needs-testing |
Focuses: | Cc: |
Description
The following suggested patch adds a new wp_get_object_terms_args
filter in wp_get_object_terms()
function in order to filter the arguments in retrieving the terms associated to the post. For example:
add_filter( 'wp_get_object_terms_args', 'wp_get_object_terms_args_hook', 10, 3 );
function wp_get_object_terms_args_hook ( $args, $object_ids, $taxonomies ) {
$args['orderby'] = 'term_order';
return $args;
}
wp_get_object_terms()
is widely used to retrieve terms taxonomies but it's not possibile to set the term_order
as orderby clause everywhere in a simple manner:
- The posts list
Even if in the post list (wp-includes/category-template.php) you can uses get_the_terms
filter to get ordered terms, you have to write additional code
- The metabox taxonomy (advanced edit)
It seems that there is no filter/hook that allow to set the term_order
as orderby for terms to edit (the terms_to_edit
filter in wp-admin/includes/taxonomy.php seems to come too late :-( )
- The XML-RCP interface
The patch filter will be used in wp_getPost()
XML-RPC interface method by returning ordered terms
Comments and suggestion are appreciated
Kindest regards
PS1: Alternatively, with the get_object_terms
filter you can do the orderby (among all other arguments) at the price to loose all the logic inside wp_get_object_terms()
so you have to rebuild the terms array from scratch.
PS2: The attached patch can be applied to 4.4.2 version too.
Attachments (8)
Change History (24)
#7
@
8 years ago
Since WP 4.7, there is a workaround. Use the filter get_terms_args
and test $args['object_ids']
to know if get_terms()
has been called directly or through wp_get_object_terms()
. Of course, this is a workaround and a dedicated filter as proposed here would offer a more robust solution.
#9
@
7 years ago
- Keywords needs-testing added
This needs review and an owner if it's going to land in 4.8.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
7 years ago
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
7 years ago
#14
@
7 years ago
- Milestone changed from 4.8.1 to 4.9
@enrico.sorcinelli Thank you for updating this patch for 4.9.
What do you think about moving the filter after the call to wp_parse_args()
? This will simplify filter callbacks, since they'll always be able to expect arrays.
To apply patch: cd /path/to/wordpress-4.4.2/wp-includes; patch -p0 < taxonomy.php-4.4.2.patch