WordPress.org

Forums

WP REST API (WP API)
[resolved] Can post content_raw but not content. Also, suggestion for small change in docs (3 posts)

  1. groberts100
    Member
    Posted 1 year ago #

    I can post articles, but the content field is ignored. Oddly the content_raw works.

    Why is the content field ignored ?

    curl -X POST http://some_user:some_password@abcdef.co.uk/wp-json.php/posts -d @post.txt

    And the file contains
    {
    "content": "Regular Content",
    "modified": "2014-01-01T14:00:00+10:00",
    "excerpt": "This is an excerpt",
    "title": "Elephants roam",
    "content_raw": "<h1>Raw Content</h1> ",
    "status":"publish",
    "type": "works" // Not post-type as the docs say
    }

    Also, I spent a while trying to post a different type of post using 'post-type' (https://github.com/WP-API/WP-API/blob/master/docs/schema.md). It works with 'type', I mis-read the docs, other people might too.

    https://wordpress.org/plugins/json-rest-api/

  2. Ryan McCue
    Member
    Plugin Author

    Posted 1 year ago #

    I can post articles, but the content field is ignored. Oddly the content_raw works.

    Why is the content field ignored ?

    The content field is the parsed content ready for output onto the page, including HTML sanitisation, shortcode replacement and oEmbed parsing. The content_raw field contains the exact data as stored in the database, and it's this value that can be edited.

    Also, I spent a while trying to post a different type of post using 'post-type' (https://github.com/WP-API/WP-API/blob/master/docs/schema.md). It works with 'type', I mis-read the docs, other people might too.

    Ah, sorry about that, the post-type bit is meant to be the ABNF for it, not the actual field name. That could be confusing though.

  3. groberts100
    Member
    Posted 1 year ago #

    Understood, thanks.

    One other thing, I'd can Post a custom post type to WordPress and see the draft article, and although I can set the name and content_raw, I have not found out how to set any of the other fields of the custom post.

    Somebody else wrote the custom post type.

    Do I need to implement extra code for the Custom Post Type or adjust the syntax of the request's body ?

    (I admit I have not read the docs for WordPress Custom Posts, I will do that now)

    Thanks again for making this useful plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP REST API (WP API)
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.