我有以下数据来自我的WP Rest API,通过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
}
]
}
}
}
我正在试图检索自定义插件中的狗类型数组。
[
"poodle",
"labrador",
"beagle",
"retriever"
]
如何通过wordpress挂钩访问上述数组?我尝试了以下方法,但没有成功:
get_taxonomy(\'dog\')->types;
$wp_taxonomies[\'dog\']->types;
下面是我试图在自定义插件中实现的代码:
$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;
}
}