Make WordPress Core

Opened 9 years ago

Last modified 7 years ago

#32993 accepted defect (bug)

get_terms with child_of only works with uninterrupted hierarchies

Reported by: eclev91's profile eclev91 Owned by: drewapicture's profile DrewAPicture
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.2.2
Component: Taxonomy Keywords:
Focuses: Cc:

Description

Similar to #14477 -

If I use get_terms() with both search and child_of, the filtered results are passed to _get_term_children(), and if those results don't include an uninterrupted heirarchy, it returns an empty array. Something like...

get_terms(array(
   'search'=>$search_term,
   'child_of'=>6
));

won't return grandchildren of 6 that match $search_term.

Change History (4)

#1 @majemedia
9 years ago

I have a workaround that just worked for me.

I had to delete an option from the DB before my child_of search worked.

Option Name: {taxonomy_name}_children

delete_option( {taxonomy_name}_children )

Then my child_of search worked wonderfully as described.

My situation:

  • Importing thousands of categories in multiple taxonomies.
  • Searching through those to assign posts, map terms from multiple taxonomies together (using WP as a tagging engine)
  • child_of wasn't working no matter what I did and did not describe in the args
  • deleted the option for all the taxonomies I am working with and it started working for grandchildren as described in the code.

This ticket was mentioned in Slack in #core by majemedia. View the logs.


9 years ago

#3 @DrewAPicture
9 years ago

  • Owner set to DrewAPicture
  • Status changed from new to accepted

#4 @eclev91
7 years ago

  • Component changed from General to Taxonomy
Note: See TracTickets for help on using tickets.