Advertisement
Guest User

Gestione POST/CUSTOM POST

a guest
Mar 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /*
  2.         Con POST    -> Si crea un nuovo post, occorre definire i campi da modificare. URL: wp/v2/custom_post
  3.         Con PUT     -> Modifica il post, occorre definire i campi da modificare. URL: wp/v2/custom_post/id
  4.         Con DELETE  -> Cancella il post. URL: wp/v2/custom_post/id
  5.     */
  6.  
  7.     $.ajax({
  8.         method: 'POST',
  9.         url: my_restapi_details.rest_url + 'wp/v2/course/45',
  10.         data: {
  11.             title: 'Giovanni truppi no',
  12.             content: '[my_sample_shortcode]',
  13.             type: 'post',
  14.             status: 'publish',
  15.             teachers: 'test',
  16.             description: 'test2'
  17.         },
  18.         beforeSend: function ( xhr ) {
  19.             xhr.setRequestHeader( 'X-WP-Nonce', my_restapi_details.nonce );
  20.         },
  21.         success : function( response ) {
  22.      
  23.             // Save the post ID in case you need it for something
  24.      
  25.             var myNewPostID = response.id;
  26.      
  27.         }
  28.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement