The $taxonomies in Exclude_tree in get_terms [0]?? Why not $taxonomies??
@param string|array
$taxonomiesTaxonomy name or list of taxonomy names.
@type array|string
$excludeArray or comma/space-separated string of term IDs to exclude.
If $include is Non-empty, $exclude is ignored. Default empty array.
@type array|string
$exclude _treeArray or comma/space-separated string of term IDs to exclude
Along with all of their descendant terms. If $include is Non-empty, $exclude _tree is ignored.
Default empty array.
@type int
$child _ofTerm ID to retrieve child terms of. If multiple taxonomies is passed, $child _of is ignored. Default 0.
@type Bool|int
$hide _emptyWhether to hide terms not assigned to any posts. Accepts
1|true or 0|false. Default 1|true.
function Get_terms($taxonomies, $args = ")
$exclusions = Array ();
if (! empty ($exclude _tree)) {
$exclude _tree = wp_parse_id_list ($exclude _tree);
$excluded _children = $exclude _tree;
foreach ($exclude _tree as $extrunk) {
$excluded _children = Array_merge (
$excluded _children,
(array) get_terms ($taxonomies [0], Array (' child_of ' = + intval ($extrunk), ' fields ' + ' IDs ', ' hide_empty ' = + 0 ) )
); Why isn't this $taxonomies??
}
$exclusions = Array_merge ($excluded _children, $exclusions);
}
if (! empty ($exclude)) {
$exclusions = Array_merge (Wp_parse_id_list ($exclude), $exclusions);
}
Reply to discussion (solution)
!--? php
$taxonomy _objects = get_object_taxonomies (' Post ', ' objects ');
Print_r ($taxonomy _objects);
?>
would output
Array
(
[Category] = StdClass Object
(
[hierarchical] + 1 [Update_count_callback] =
[rewrite] =
[Query_var] = Category_name
[public] + 1
[sho W_UI] = 1
[Show_tagcloud] = 1
[_builtin] + 1
[labels] + stdClass Object
(
...
)
...
[Name] = category
[Label] = Categories
)
[Post_tag] + stdClass Object
(
...
)
[Post_format] = StdClass Object
(
....
)
)
up to $taxonomies [0]
From the above can be seen, $taxonomies [0] = Category
We know that Post_tag does not have the parent property. This method is for! Empty ($exclude _tree) is for category.
The coder calls the category directly, although there is no problem, but I think, there is a bug, there is a hidden danger.
I do not know how to see this problem master.
@param string|array $taxonomies Taxonomy name or list of taxonomy names category names or category name lists
So $taxonomies is a string or an array
The use of $taxonomies without judgment [0] is wrong!
The moderator was right. In the WordPress manual http://codex.wordpress.org/Function_Reference/get_terms
In the example cited:
No default values. Using these as examples
$taxonomies = Array (
' Post_tag ',
' My_tax ',
);
$args = Array (
' By ' = ' and ' name ',
' Order ' = ' ASC ',
' Hide_empty ' = true,
' Exclude ' = = Array (),
' Exclude_tree ' = = Array (),
' Include ' + = Array (),
' Number ' = ',
' Fields ' = ' all ',
' slug ' = ',
' Parent ' = ',
' Hierarchical ' = true,
' child_of ' = 0,
' Childless ' = false,
' Get ' and ' = ',
' Name__like ' = ',
' Description__like ' = ',
' Pad_counts ' = False,
' Offset ' = ',
' Search ' = ',
' Cache_domain ' = ' core '
);
$terms = Get_terms ($taxonomies, $args);
?>
$taxonomies [0] = "Post_tag"
----In this case, Get_terms is still working, because its parameters prevent it from causing problems. If
If this is really the problem, please Gao Yun write to the WordPress development team
The answer is in the description of the parameter child_of: $child _of term ID to retrieve child terms of. If multiple taxonomies is passed, $child _of is ignored.
In other words, the array $taxonomies can have only one element.