I am trying to pass an array of category IDs to get_category_by_ID()
in order to get an array of category names back. Since I'm still trying to get this to work I'm just using var_dump()
on the output. I'm using the values 1, 5, 3 since 5 and 3 are categories I have and 1 is uncategorized, which I need this to work for.
I started with this:
$CatID = array(1, 5, 3,);
foreach ($CatID as $ID) {
$names = get_the_category_by_ID($ID);
}
var_dump($names);
I returned the correct category name for category 3, but nothing else. So then I tried it like this:
$CatID = array(1, 5, 3,);
$x=0;
foreach ($CatID as $ID) {
if ($x==3) break;
$names[$x] = get_the_category_by_ID($ID[$x]);
$x++;
}
var_dump($names);
This time I got this array of errors:
array
0 =>
object(WP_Error)[262]
public 'errors' =>
array
'invalid_term' =>
array
...
public 'error_data' =>
array
empty
1 =>
object(WP_Error)[261]
public 'errors' =>
array
'invalid_term' =>
array
...
public 'error_data' =>
array
empty
2 =>
object(WP_Error)[215]
public 'errors' =>
array
'invalid_term' =>
array
...
public 'error_data' =>
array
empty