wordpress-java library:发布特定类别的帖子

时间:2018-02-12 22:18:21

标签: java wordpress

有一个图书馆:https://github.com/canbican/wordpress-java

如何将帖子发布到特定的WP类别?例如 类别名为" General"。如何将帖子发布到常规类别?

这是我的代码:

        Post recentPost = new Post();
        recentPost.setPost_parent(2);
        term1.setTaxonomy("General"); //This parameter does not post in category of General
        recentPost.setPost_title(title);
        recentPost.setPost_content("Test description");
        recentPost.setPost_status("draft");
        recentPost.setPost_parent(9);
        Integer result = wp.newPost(recentPost);

1 个答案:

答案 0 :(得分:0)

final Term term1 = wp.getTerm("category", 2);
        final Term term2 = wp.getTerm("category", 3);

        Post recentPost = new Post();
        recentPost.setTerms(Arrays.asList(new Term[] {term1, term2}));
//        recentPost.setPost_parent(3);
        recentPost.setPost_title(title);
        recentPost.setPost_content("Test description");
        recentPost.setPost_status("draft");
        recentPost.setPost_parent(9);
//        recentPost.setPost_thumbnail("sd");
        Integer result = wp.newPost(recentPost);