在插入帖子时插入post元值的wordpress rest api问题

时间:2018-03-07 10:55:15

标签: wordpress rest

这是我的代码。使用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>

0 个答案:

没有答案