感谢@sallyCJ修复我的错误!下面是WP-API主干JS客户端的一些示例。它可以帮助他人:
获取某个作者和类别的帖子:
var filteredPosts = new wp.api.collections.Posts();
authorsPosts.fetch({ data: { author: currentUserId, categories: 42 } }).then( posts => {
for(const post of posts){
//do stuff with each post
}
} );
更新帖子:
var post = new wp.api.models.Post( {
id: idOfThePostYouWantToUpdate,
title: newTitle,
content: newContent,
status: newStatus,
categories: [ 42 ],
tags: [ 50 ]
});
post.save();