WordPress.org

Forums

JSON API
create post - send attachment (2 posts)

  1. dvirh
    Member
    Posted 1 year ago #

    I'm building a web application based on wordpress & wp json plugin.

    I created a form for posting a new post with title, content and attachment but the attachment is not passing on

    js:

    $(document).on("submit", "#add-post #post-upload", function(e) {
    
        var post_title = $("#add-post input[name='form-post-title']").val();
        var post_content = $("#add-post textarea[name='form-post-content']").val();
    
        $.ajax({
            url: url + "/create_post?nonce=*******&title=" + post_title + "&content=" + post_content,
            dataType: "json",
            success: function(data){
                console.log(data);
            },
            error: function(data) {
                console.log(data);
            }
        });
    });

    html code:

    <form name="post-upload" id="post-upload" method="post" action="#home" enctype="multipart/form-data">
            <input type="text" name="form-post-title" placeholder="title" />
            <textarea name="form-post-content" placeholder="content"></textarea>
            <input type="file" name="attachment" id="attachment" />
            <input type="submit" value="Submit" />
        </form>

    wordpress json api github page (https://github.com/homicidewatch/wordpress-json-api) says it needs to have a input with "attachemnt" as a name for file input. But again, not working for some reason.

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

  2. vespino
    Member
    Posted 7 months ago #

    Have you been able to solve this? I'm also looking for a way to upload an attachment.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • JSON API
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic