You are using third party code to generate those meta boxes, and I am not familiar with how that code works. In fact, based on your question I am not even sure exactly where the code fails. Your description of the problem is inadequate. I can point out that your code is overly complex. It can be simplified considerably:
function get_destinations(){
// Using a post type
$args = array(
'type' => 'book',
'taxonomy' => 'genre',
);
$categories = get_terms($args); // changed to get_terms()
if (!is_wp_error()) {
$destinations = wp_list_pluck($categories,'cat_name');
/* Convert to key=>value format
I doubt this is actually necessary and can probably be omitted
*/
$destinations = array_combine($destinations,$destinations);
return $destinations;
}
}
var_dump(get_destinations());
- Remove the default arguments. You don’t need to repeat those.
- Use
get_terms()
as it returns a properWP_Error
object instead
of only a part of one (at least on my install, which I may have
broken. I do that periodically). At any rate,get_terms()
makes
more since as you are not retrieving “categories” but a custom
taxonomy. - Verify that you have proper term results before trying to use them
- Use
wp_list_pluck()
to simplify theforeach
As far as Core code, I only see three places where this can fail:
- The post type is wrong
- The taxonomy is wrong
- There are not posts in the type/taxonomy