WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
create post - send attachment (1 post)

  1. dvirh
    Member
    Posted 2 months 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/

Reply

You must log in to post.

About this Plugin

About this Topic