[英]Trying To Populate Array w/ List of Categories from a Custom Taxonomy
I am trying to populate an array with a list of categories in a custom taxonomy I created. 我试图用我创建的自定义分类法中的类别列表填充数组。
The taxonomy's slug is "clipcat". 分类法的标准是“夹杂物”。 I only want the array to populate with children of a clip with the same slug as the page slug the list is on. 我只希望数组中填充一个子片段,而子片段与列表中的页面子片段具有相同的子片段。
Here's my code so far: 到目前为止,这是我的代码:
<?php
global $post;
$slug = get_post( $post )->post_name;
echo $slug;
$taxes = array('clipcat');
$args = array(
'parent' => $slug,
);
$categories = get_terms( $taxes, $args );
?>
<p>
<?php print_r($categories); ?>
</p>
You can see what this code outputs here: http://noellesnotes.com/portfolio/seventeen/ 您可以在此处查看此代码的输出: http : //noellesnotes.com/portfolio/seventeen/
To my knowledge, the code is as it should be, but when I print the array (the last line in the code), the array is empty even though I know the clip category that is successfully assigned to $slug has three sub categories (so I must be coding something wrong). 据我所知,代码是应该的,但是当我打印数组(代码的最后一行)时,即使我知道成功分配给$ slug的剪辑类别有三个子类别,该数组也为空(因此我必须编码错误)。
Any help would be GREATLY appreciated! 任何帮助将不胜感激!
Thanks! 谢谢!
According to the get_terms
documentation, the parent
key requires an integer: 根据get_terms
文档, parent
键需要一个整数:
"Parent (integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string" “父级(整数)获取此术语的直接子级(仅其显式父级为此值的术语)。如果传递0,则仅返回顶级术语。默认值为空字符串”
I believe you are passing a string 我相信你正在传递一个字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.