How do I get array of types associated with a taxonomy?
Question
I have the following data coming from my WP Rest API via https://cms.dboxcg.com/index.php/wp-json/wp/v2/taxonomies
:
{
"category": {
"name": "Categories",
"slug": "category",
"description": "",
"types": [
"post"
],
"hierarchical": true,
"rest_base": "categories",
"_links": {
"collection": [
{
"href": "https://cms.dboxcg.com/index.php/wp-json/wp/v2/taxonomies"
}
],
"wp:items": [
{
"href": "https://cms.dboxcg.com/index.php/wp-json/wp/v2/categories"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
"post_tag": {
"name": "Tags",
"slug": "post_tag",
"description": "",
"types": [
"post"
],
"hierarchical": false,
"rest_base": "tags",
"_links": {
"collection": [
{
"href": "https://cms.dboxcg.com/index.php/wp-json/wp/v2/taxonomies"
}
],
"wp:items": [
{
"href": "https://cms.dboxcg.com/index.php/wp-json/wp/v2/tags"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
"dog": {
"name": "Dogs",
"slug": "dog",
"description": "",
"types": [
"poodle",
"labrador",
"beagle",
"retriever"
],
"hierarchical": false,
"rest_base": "dog",
"_links": {
"collection": [
{
"href": "https://cms.dboxcg.com/index.php/wp-json/wp/v2/taxonomies"
}
],
"wp:items": [
{
"href": "https://cms.dboxcg.com/index.php/wp-json/wp/v2/dog"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
}
I am trying to retrieve the array of dog types in a custom plugin.
[
"poodle",
"labrador",
"beagle",
"retriever"
]
How do I access the above array via wordpress hooks? I have tried the following with no luck:
get_taxonomy('dog')->types;
$wp_taxonomies['dog']->types;
Here is the code I am trying to implement in a custom plugin:
$dog_types = get_taxonomy('dog')->object_type;
foreach ($dog_types as $type) {
add_filter( "manage_{$type}_posts_columns", 'update_dog_type_columns' );
add_action( "manage_{$type}_posts_custom_column", 'update_dog_type_column', 10, 2 );
}
function update_dog_type_columns( $columns ) {
$columns = array(
'cb' => $columns['cb'],
'title' => __( 'Title' ),
'image' => __( 'Thumbnail' ),
'date' => __( 'Date' )
);
return $columns;
}
function update_dog_type_column( $column, $post_id ) {
switch ( $column ) {
case 'image':
$vimeo_link = get_field('vimeo_link');
if ($vimeo_link) {
$vimeo_logo_url = 'https://imageurl/vimeo_logo.jpg';
echo '<img src="' . $vimeo_logo_url . '" height="100px" width="100px" />';
break;
} else {
$img_array = get_field('image');
$img = $img_array['sizes']['thumbnail'];
echo '<img src="' . $img . '" height="100px" width="100px" />';
break;
}
case 'year':
echo get_field( 'year', $post_id );
break;
}
}
0
custom-post-types, custom-taxonomy, taxonomy
3 years
2020-04-03T20:50:58-05:00
2020-04-03T20:50:58-05:00 0 Answers
85 views
0
Leave an answer