Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Created May 14, 2014 04:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mikeschinkel/39ea071cc98e0fee18e6 to your computer and use it in GitHub Desktop.
Proposal for interface of Post Meta in the WordPress REST API. - Make comment at: http://wpapiteam.wordpress.com/2014/05/12/handling-post-meta/#comment-435

##Data: { "post_meta": [ { "ID": 33, "key": "my_key", "value": "value1" }, { "ID": 34, "key": "my_other_key", "value": "value1" }, { "ID": 35, "key": "my_other_key", "value": "value2" } ] } ##For Updating Meta:

###To Update a Meta Row (note the id= is optional and not needed)

PUT /posts/{post_id}/meta/id={meta_id}/
{
    "post_meta": [
        {
            "key": "my_key",
            "value": "newvalue1"
        }
    ]
}

###To Update a Meta Key: This would update one 'meta_key' and delete any others if the key has more values than included.)

(note the key= is optional and only needed if is_numeric($meta_key) is true.)

PUT /posts/{post_id}/meta/key={meta_key}/
{
    "post_meta": [
        {
            "key": "my_key",
            "value": "newvalue1"
        }
    ]
}

###To Update All Meta for a Post This would update any meta rows and/or meta keys provided and delete any others for the post that are no specified.

PUT /posts/{post_id}/meta/
{
    "post_meta": [
        {
            "ID": 33,
            "key": "my_key1",
            "value": "newvalue1"
        },
        {
            "key": "my_key2",
            "value": "newvalue2"
        }
    ]
}

###To Update Only Specific Meta for a Post This would update only the meta specified and leave all other intact. If an ID is specified it would affect the row, if a key specified it would affect all rows with the key.

PATCH /posts/{post_id}/meta/
{
    "post_meta": [
        {
            "ID": 33,
            "key": "my_key1",
            "value": "newvalue1"
        },
        {
            "key": "my_key2",
            "value": "newvalue2"
        }
    ]
}

##For Adding Meta:

###To Add a Meta Key: This would add one or more rows for a 'meta_key', or overwrite any that exist with the same key value. This would not delete existing rows with the same key.

POST /posts/{post_id}/meta/
{
    "post_meta": [
        {
            "key": "my_key",
            "value": "newvalue1"
        },
        {
            "key": "my_key2",
            "value": "newvalue2"
        }
    ]
}

##For Deleting Meta:

###To Delete a Meta Row (note the id= is optional and not needed)

DELETE /posts/{post_id}/meta/id={meta_id}/

###To Delete a Meta Key: This would delete all rows with the specified 'meta_key'.

(note the key= is optional and only needed if is_numeric($meta_key) is true.)

DELETE /posts/{post_id}/meta/key={meta_key}/

###To Delete All Meta for a Post This would delete any meta rows for the post.

DELETE /posts/{post_id}/meta/
@mikeschinkel
Copy link
Author

Make any comments on the WordPress Make blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment