Search taxonomy term's children by name

Public

</> CopyGet raw version
php
  1. /**
  2.  * Search in term's children by name.
  3.  *
  4.  * @param $child_name
  5.  * A string of child term to search.
  6.  * @param $pid
  7.  * Term id of parent
  8.  * @param $vid
  9.  * Vocabulary id to limit the search.
  10.  *
  11.  * @return
  12.  * An array of term objects, indexed by tid.
  13.  * When no results are found, an empty array is returned.
  14.  */
  15.  
  16. function hook_get_term_children_by_name($child_name, $pid, $vid) {
  17. // List of children terms.
  18. $child_tids = array_keys(taxonomy_get_children($pid));
  19. if (count($child_tids) == 0) {
  20. // Term has no children.
  21. return array();
  22. }
  23. $conditions = array('name' => trim($child_name), 'vid' => $voc['id']);
  24. $terms = taxonomy_term_load_multiple($child_tids, $conditions);
  25. return $terms;
  26. }