2017-10-18 33 views
0

我想以編程方式設置自定義分類的條款。WordPress的設置對象條款不起作用

因此,這裏是我的代碼..

$test = wp_set_post_terms(11452, 189,'jobs_sub_categories_taxonomy', false); 

現在正常的和帖子ID的單詞ID將被從其他地方但我已經進入了它的測試取我得到的回報是:

var_dump($test); 

array(1) { [0]=> string(3) "189" } 

現在從查看Codex數組中應該列出已更改的內容。但是,當我通過儀表板查看帖子時,自定義類別沒有被選中「打開」。我在這裏錯過了什麼嗎?

+0

? – madalinivascu

回答

1

如果您通過here閱讀了法典中的下一頁,您會看到該術語需要是一個數組。

<?php wp_set_post_terms($post_id, $terms, $taxonomy, $append) ?> 

這裏是你的**,他自定義類別未選中「上」 **意味的解釋

$tag = '5'; // Wrong. This will add the tag with the *name* '5'. 
$tag = 5; // Wrong. This will also add the tag with the name '5'. 
$tag = array('5'); // Wrong. Again, this will be interpreted as a term name rather than an id. 

$tag = array(5); // Correct. This will add the tag with the id 5. 

wp_set_post_terms($post_id, $tag, $taxonomy); 
+0

謝謝,現在工作:)我會盡可能地解決問題! – Mark