#56630 closed defect (bug) (worksforme)
get_terms() does not recognize the 'slug' argument
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | needs-patch |
Focuses: | Cc: |
Description
Description
When passing a slug to the get_terms() function, returned results are not filtered by that slug.
Steps to reproduce
- In a theme template or plugin file, query for a known existing term in a taxonomy with get_terms(). For example: get_terms( [ 'taxonomy' => 'custom_tax_name', 'slug' => 'existing-slug'] );
- Dump the contents of the get_terms query.
Expected outcome
Results show only those terms matching the slug.
Actual outcome
Results show all terms in the taxonomy.
Change History (4)
#2
@
2 years ago
@NemesisVex hello and welcome to trac!
I've attempted to reproduce this using WordPress 6.0.2 but without success. Are you able to check this running a default theme and without any plugins enabled?
This is a dump of running the command within wp-cli, each command returns the single term as expected:
wp> get_terms( [ 'taxonomy' => 'custom-taxo', 'slug' => 'term-1'] ); => phar:///usr/local/src/wp-cli/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php:52: array(1) { [0] => class WP_Term#2612 (10) { public $term_id => int(9) public $name => string(6) "Term 1" public $slug => string(6) "term-1" public $term_group => int(0) public $term_taxonomy_id => int(9) public $taxonomy => string(11) "custom-taxo" public $description => string(0) "" public $parent => int(0) public $count => int(1) public $filter => string(3) "raw" } } wp> get_terms( [ 'taxonomy' => 'custom-taxo', 'slug' => 'term-2'] ); => phar:///usr/local/src/wp-cli/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php:52: array(1) { [0] => class WP_Term#2614 (10) { public $term_id => int(10) public $name => string(6) "term 2" public $slug => string(6) "term-2" public $term_group => int(0) public $term_taxonomy_id => int(10) public $taxonomy => string(11) "custom-taxo" public $description => string(0) "" public $parent => int(0) public $count => int(1) public $filter => string(3) "raw" } }
#3
@
2 years ago
- Resolution set to worksforme
- Status changed from new to closed
I'm closing this ticket.
Upon further inspection of the client site that generated this bug report, the taxonomy being passed to the 'taxonomy' argument was being generated by a third party plugin. On this same client site, using a default taxonomy such as 'post_tag' or a properly registered taxonomy using register_taxonomy() does not result in the reported behavior.
I've already advised the client about the plugin in question.
Thank you!
There we changes here 6 months ago that would be suspect. https://github.com/WordPress/wordpress-develop/blame/2bb5679d666474d024352fa53f07344affef7e69/src/wp-includes/class-wp-term-query.php#L554-L564