2015-11-29 47 views
0

我在節點中有一個簡單的腳本,但是問題與一般的API有關。Wordpress API,帶有類別和標籤的新帖子

我可以通過API輕鬆創建新帖子,但無法添加類別或標籤。

我的代碼:

client.newPost({ 
    title: 'title of the post', 
    status: 'publish', 
    type: 'post', 
    content: 'content of the post', 
    categories: ["category1", "category2"] 
}, function(err, id) { 
    if (err) console.log(err) 
    else console.log(id) 
}); 

我只貼有趣的部分,其餘的偉大工程。 讓我們甚至說這些類別存在。

回答

0

調試完wordpress代碼庫後,我找到了這個問題的解決方案。

正如我所說這個API是爲node-wordpress,但它可能有助於其他apis,因爲我沒有在其他地方找到答案。

您只需使用此

wordpress.newPost({ 
    title: title, 
    status: 'publish', 
    type: 'post', 
    content: content, 
    terms: { 
     category: [2], 
     post_tag: [3] 

    }, 
    tags: 'bling' 


}, function(err, id) { 
    if (err) console.log(err) 
    else console.log(id) 
}); 

正如你可以看到你有「術語」 和裏面,你有「類」和「post_tag」。

目前您只能傳遞ids,它們應該存在於wordpress目標中,否則會失敗。

相關問題