wpmetabox / mb-rest-api

Add custom fields to WordPress REST API
19 stars 12 forks source link

Term meta not saved for custom taxonomies #9

Closed mpandzo closed 5 years ago

mpandzo commented 5 years ago

When a custom taxonomy is created via POST request to rest api, the meta box fields are not saved on said request.

e.g. create a new custom taxonomy called Article tag. When registering the taxonomy make sure the rest api properties are set:

'show_in_rest'          => true,
'rest_base'             => 'video-tags',            
'rest_controller_class' => 'WP_REST_Terms_Controller', 

Register a simple meta box text field with your custom taxonomy.

array(
    'id' => 'video_id',
    'name' => esc_html__( 'Video ID', 'digg-core' ),
    'type' => 'text',
)

A subsequent POST request to /wp-json/wp/v2/article-tags will result in a new tag being created with the parameter video_id value not set. The parameters passed in are:

"title": "A test video tag",
"meta_box": "{
    "video_id": "12345"
}"
mpandzo commented 5 years ago

I have created a pull request that resolves this for custom taxonomies: https://github.com/wpmetabox/mb-rest-api/pull/10

rilwis commented 5 years ago

Thanks a lot for your PR. As it's merged, I'll close this issue.