这是我的代码。使用WordPress REST API
插入新帖子时出现问题。使用给定的代码,Post已成功插入,但post meta字段仍为空。
<script type="text/javascript">
jQuery( document ).ready( function ( $ ) {
//Create Cause
$( '#frm_create_campaign' ).on( 'submit', function(e) {
e.preventDefault();
var title = $('#cmp_title').val();
var content = $('#post_submission_content').val();
var meta = {'gdlr-current-funding':"0"};
var status = 'draft';
var data = {
title: title,
content: content,
meta: meta
};
$.ajax({
method: "POST",
url: POST_SUBMITTER.root + 'wp/v2/cause',
data: data,
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', POST_SUBMITTER.nonce );
},
success : function( response ) {
console.log( response );
alert( POST_SUBMITTER.success );
},
fail : function( response ) {
console.log( response );
alert( POST_SUBMITTER.failure );
}
});
});//End Create Cause
</script>