Custom Fields
Re-Envisioned
Support MB REST API POST meta fields to tags Reply To: POST meta fields to tags

#12059

mp81
Participant

I 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;
    }
}