Ok So I'm using wordpress and PHP.
Basicly I get a chosen category from a dropdown menu. I then find it's parents.
But then comes the part where I seem to fail. The output of $parents is a string with the names instead of the ID's.
So I try to get each word from the string into an array. And loop through them and convert them to their ID number.
I commented out where it doesnt seem to work. What am I doing wrong?
//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"];