Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#56630 closed defect (bug) (worksforme)

get_terms() does not recognize the 'slug' argument

Reported by: nemesisvex's profile NemesisVex 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

  1. 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'] );
  2. 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 @peterwilsoncc
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 @NemesisVex
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!

#4 @peterwilsoncc
2 years ago

  • Milestone Awaiting Review deleted
  • Version 6.0.2 deleted

Thanks for the follow up, it's really appreciated.

Note: See TracTickets for help on using tickets.