2017-10-18 7 views
0

カスタム分類法の用語をプログラムで設定しようとしています。だからここWordpress setオブジェクトの用語が正しく動作しない

は、私が持っているコード..です

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

は今通常postidと用語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

関連する問題