[wp-trac] [WordPress Trac] #40697: Can't create new post by REST API but I can update existing post

WordPress Trac noreply at wordpress.org
Tue May 9 00:42:47 UTC 2017


#40697: Can't create new post by REST API but I can update existing post
--------------------------+-----------------------------
 Reporter:  Alaa Rihan    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.7.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi,

 I'm trying to let users create/edit/delete posts from frontend using
 WordPress REST API, everything working but creating new post, this is my
 code

 {{{
 jQuery( document ).ready( function ( $ ) {
     $( '.add-new-project button' ).click( function(e) {
         var title = 'test111';
         var excerpt = 'ssss';
         var content = 'cdffddfsf';
         var status = 'draft';

         var data = {
             title: title,
             excerpt: excerpt,
             content: content
         };

         $.ajax({
             method: "POST",
             url: apiData.apiURL + 'wp/v2/posts',
             data: data,
             beforeSend: function ( xhr ) {
                 xhr.setRequestHeader( 'X-WP-Nonce', apiData.nonce );
             },
             success : function( response ) {
                 console.log( response );
             },
             fail : function( response ) {
                 console.log( response );
             }

         });

     });

 } );
 }}}


 This the the response I get when I try to create post:
 {{{
 {code: "rest_no_route", message: "No route was found matching the URL and
 request method",…}
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40697>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list