Selective fetch meta data via rest api

Support MB REST API Selective fetch meta data via rest api

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32733
    DaveDave
    Participant

    Hi,

    I'm probably doing something wrong, but I'm trying to fetch a restricted set of meta fields from a post using the REST API.

    /wp-json/wp/v2/book/16

    Returns a field containing all data

        "meta_box": {
            "url": "https://google.com",
            "text": "asdfasdf"
        },

    But when I try to select a single value I get 0 values.

    /wp-json/wp/v2/book/16?_fields=meta_box

    returns

    "meta_box": [],

    What I am trying to get is a query that returns only specific Meta Box values. ie just meta_box.url

    eg /wp-json/wp/v2/book/16?_fields=title.rendered,excerpt.rendered,meta_box.url

    to get something like

        "title": {
            "rendered": "The Harder We Fall"
        },
        "excerpt": {
            "rendered": "<p>Insomnia. It’s part of the penance I pay for my greatest mistake. But when an ill-timed doze behind the wheel of my car nearly introduces me to a pole, I know something has to change.</p>\n"
        },
        "meta_box": [
           "url": "https://google.com"
    ],

    My googling has returned nothing useful for me. Your assistance would be appreciated.

    #32745
    Long NguyenLong Nguyen
    Moderator

    Hi,

    As far as I know, WP REST API supports fetching fields for all posts, not for a specific post. And it looks like meta box is not supported to fetch in this way. Refer to this topic https://stackoverflow.com/questions/36339689/how-to-specify-the-fields-to-wordpress-api-v2

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