Support Forum » User Profile

Forum Replies Created

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • in reply to: POST meta fields to tags #12150
    mp81mp81
    Participant

    Awesome thanks. You can close this issue!

    in reply to: POST meta fields to tags #12147
    mp81mp81
    Participant

    Hi 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

    in reply to: MB Term Meta and MB Rest API not working #12136
    mp81mp81
    Participant

    I have provided solutions to these issues in this thread:
    https://support.metabox.io/topic/post-meta-fields-to-tags

    in reply to: POST meta fields to tags #12135
    mp81mp81
    Participant

    For 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.

    in reply to: POST meta fields to tags #12134
    mp81mp81
    Participant

    Just 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.

    in reply to: POST meta fields to tags #12102
    mp81mp81
    Participant

    Hi Anh,

    Any news with regards this?

    Thanks,

    in reply to: POST meta fields to tags #12077
    mp81mp81
    Participant

    I 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.

    in reply to: POST meta fields to tags #12059
    mp81mp81
    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;
        }
    }
    in reply to: POST meta fields to tags #12043
    mp81mp81
    Participant

    Ie how would you go about adding fields to the tags... your meta terms extension is enabled and so is the rest api extension.

    in reply to: POST meta fields to tags #12042
    mp81mp81
    Participant

    Hi 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.

Viewing 10 posts - 1 through 10 (of 10 total)