获取父级层次结构的最佳方法是什么category objects 从category.php
模板,当没有这样的帖子时。
功能get_category_parents()
返回字符串而不是对象。
功能get_categories()
似乎是针对有帖子的页面,因为type
参数可以采用post
或link
.
我是否缺少其他功能?我需要一个行为完全像get_category_parents()
但我需要的是类别对象,而不仅仅是所有名称的字符串。
获取父级层次结构的最佳方法是什么category objects 从category.php
模板,当没有这样的帖子时。
功能get_category_parents()
返回字符串而不是对象。
功能get_categories()
似乎是针对有帖子的页面,因为type
参数可以采用post
或link
.
我是否缺少其他功能?我需要一个行为完全像get_category_parents()
但我需要的是类别对象,而不仅仅是所有名称的字符串。
我不知道有什么内置函数可以满足您的要求,但这并不难编造。事实上,你很接近。get_categories
是正确的,但它需要child_of
参数,这意味着通过get_ancestors
. child_of
将只返回子级,而不是指定的父级,因此必须手动将父级插入到结果中。
var_dump(get_category_parents(5)); // reference
$anc = get_ancestors(5,\'category\');
$parent = array_pop($anc);
$hier[] = get_category($parent);
$args = array(
\'child_of\' => $parent,
);
array_push($hier,get_categories($args));
var_dump($hier);
我有一个自定义的帖子类型,它有自己的分类法,基本上“show Vinces”是帖子类型,Vincement regions是分类法。看到一个场馆无法在多个地区存在,我删除了默认的metta框,并使用wp_dropdown_categories(). 分类法项目正在输出并按我所希望的方式显示,但它们不会被提交,并且下拉列表在提交后不会保留所选内容。我已经尽我所能地查看原始metabox的各种属性,并尝试将这些属性应用到下拉列表中,但到目前为止,我没有任何乐趣。我看过一些various WPSE上的帖子和ha