且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Wordpress,从URL获取多个类别的ID

更新时间:2023-11-26 10:36:52

感谢Manzabar的回答,我可以从您的代码中对其进行修改,以得到什么我想要。

Thanks for the answer Manzabar, from your code i was able to modify it to get what i wanted.

最终,我想要一个数组,其中包含该类别的parentID。这是我的操作方式:

Ultimately, I wanted an array of the category's parentIDs. Here's how I did it:

$parents = get_category_parents($cat, false, '^%%^');
$parents = explode('^%%^', $parents);
$parentIDs = array();
foreach($parents as $parent){
    if (is_null($parent) || empty($parent)){
        continue;
    }
    $parentIDs[] = get_cat_ID($parent);
}
echo '<pre>';
print_r($parentIDs);
echo '</pre>';

请注意,$ cat拥有当前类别ID

Note that $cat holds the current categoryID