JavaScript for WordPress Forums The WP REST API Add meta fields to WP REST API for Tags

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #25843
    Adrian (AT)
    Participant

    Hi,

    From my own research, I managed to register a new postmeta and output the field to the WP REST API for Posts.
    register_rest_field( ‘post’, ‘newPostField’, array(
    ‘update_callback’ => null,
    ‘schema’ => null,
    ‘get_callback’ => function ( $data ) {
    return get_post_meta( $data[‘id’], ‘postmeta’, ‘true’ );
    }, ));

    I tried to do the same to register a new termmeta but unable to get it to work like the above.
    register_rest_field( ‘terms’, ‘newTermField’, array( //tried to use ‘post_tag’ instead of ‘terms’ but it don’t work. Suspect the problem is here
    ‘update_callback’ => null,
    ‘schema’ => null,
    ‘get_callback’ => function ( $data ) {
    return “test”; //get_term_meta( $data[‘id’], ‘termmeta’, ‘true’ ); //test also don’t show up
    }, ));

    Appreciate if you can provide advice on this.
    Thanks.

    #25863
    Zac Gordon
    Keymaster

    This is getting a bit beyond what we have officially covered so far, but a good question.

    Does this setup here help?

    https://wordpress.stackexchange.com/questions/250614/create-taxonomy-with-meta-term-using-the-wp-rest-api

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.