我想让用户能够从前端创建各种自定义帖子,但根据指定的分类,返回链接到它的自定义帖子表单。因此,在获得所选分类法之后,我无法检查get\\u terms()请求中是否存在该分类法
我认为这是因为in\\u array()函数在多维数组方面做得不好。因此,我在这里搜索并找到了一种方法来生成另一个克服该问题的函数,但它仍然不起作用
这是我的代码:
<?php
$cptTax = $_GET[\'choosetax\'];
$tax1List = get_terms([
\'taxonomy\' => \'tax1\',
\'hide_empty\' => false,
]);
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
if( in_array_r($cptTax, $tax1List, false)): ?>
<form action="action" method="post" enctype="multipart/form-data">
我用var\\u dump()检查了$tax1List变量,并且slug就在那里。。。但函数返回false<谢谢你的帮助