Forum Replies Created
-
AuthorPosts
-
mp81
ParticipantAwesome thanks. You can close this issue!
mp81
ParticipantHi Anh,
Thanks for merging. https://github.com/wpmetabox/mb-rest-api/blob/master/class-mb-rest-api.php looks ok now except you have some indentation issues on lines 56 to 62.
best regards
mp81
ParticipantI have provided solutions to these issues in this thread:
https://support.metabox.io/topic/post-meta-fields-to-tagsmp81
ParticipantFor anyone following, I have found a fix for the post_tag not having it's meta values saved as well.
In order to fix this one must edit mb-rest-api/class-mb-rest-api.php and change
`register_rest_field( $this->get_types('taxonomy'), 'meta_box', array( 'get_callback' => array( $this, 'get_term_meta' ), 'update_callback' => array( $this, 'update_term_meta' ), ) );`to
$taxonomies = $this->get_types('taxonomy'); if (in_array("post_tag", $taxonomies)) { $post_tag_key = array_search('post_tag', $taxonomies); $taxonomies[$post_tag_key] = 'tag'; } register_rest_field( $taxonomies, 'meta_box', array( 'get_callback' => array( $this, 'get_term_meta' ), 'update_callback' => array( $this, 'update_term_meta' ), ) );This is because there appears to be a bug in WordPress rest api itself where it checks for 'tag' instead of 'post_tag' when looking for additional fields.
mp81
ParticipantJust an update for this for anyone following, I found a partial solution that fixes posting custom taxonomies with meta_box parameter via rest api.
In file mb-rest-api/class-mb-rest-api.php line 155 is
$field = rwmb_get_registry( 'field' )->get( $field_id, $object->taxonomy);It should in fact be:
$field = rwmb_get_registry( 'field' )->get( $field_id, $object->taxonomy, 'term' );I will continue investigating why builtin taxonomies do not get their meta_box fields passed in and saved at all.
mp81
ParticipantHi Anh,
Any news with regards this?
Thanks,
mp81
ParticipantI have investigated this further and I found out that saving meta_box data only does not work for builtin taxonomies: so for post_tags and categories.
If I register a custom taxonomy, everything works as it should.
Any ideas why meta fields for builtin taxonomies do not save? and the update_term_meta never triggers for them, while it triggers fine for a custom taxonomy.
mp81
ParticipantI have been checking this further, and for me at least, in class-mb-rest-api.php the update_term_meta update_callback never gets triggered.
This is when I use for the tags endpoint:
POST to /wp-json/wp/v2/tags with parameters:
name: A tag
slug: a-tag
description: A tag
meta_box: { 'an_existing_field': 'abc' }Result: update_term_meta NOT TRIGGERED
This is when I use for the posts endpoint:
POST to /wp-json/wp/v2/posts with parameters:
title: A tag
slug: a-tag
description: A tag
meta_box: { 'an_existing_field': 'abc' }Result: update_post_meta TRIGGERED
Btw, you have the following code inside both update_term_meta and update_post_meta
if ( is_string( $data ) ) { $data = json_decode( $data, true ); if ( JSON_ERROR_NONE === json_last_error() ) { return; } }I believe this should instead be
if ( is_string( $data ) ) { $data = json_decode( $data, true ); if ( JSON_ERROR_NONE !== json_last_error() ) { return; } }mp81
ParticipantIe how would you go about adding fields to the tags... your meta terms extension is enabled and so is the rest api extension.
mp81
ParticipantHi Anh,
Thanks for a quick reply.
I don't think I made myself clear however.
I am trying to submit A POST request via REST api. According to the docs for rest api https://docs.metabox.io/extensions/mb-rest-api/ to submit field values, one must pass in a field called meta_box.
This works fine for creating a post. However, when using your terms extension, and passing in the meta_box parameter, the same does not work.
-
AuthorPosts