好的,我可以从wp下拉列表中得到一个选择。这个选择是一个类别。我用这个类别来找它的父母。这好像是在输出一根线。
应将此字符串转换为数组。然后,我需要遍历数组并将类别名更改为类别ID。
但出于某种原因,这似乎行不通。我做错什么了?我评论了不起作用的地方。
(此数组用于与post_category一起创建新的post。)
//Create array
$categoriesArray = [];
//Get choice from wp-dropdown
$selected_val = $_POST['cat'];
//Get parents from choice divided by (this seems to output a string)
$parents = get_category_parents( $selected_val, true, ',' );
/*
//Make array from string
$categoriesArray = explode(",",$parents);
for ($i = 0; $i < count($categoriesArray); $i++) {
{
$categoriesArray[$i] = get_cat_ID($categoriesArray[$i]);
}
*/
//the array should look something like this.
//$categoriesArray = ["21","44"];发布于 2018-10-12 07:55:37
get_category_parents()的第二个参数定义了是否应该创建指向类别的链接。如果你把它设为假的话,我猜它会起作用的。
https://wordpress.stackexchange.com/questions/316494
复制相似问题