我正在尝试通过我从插件文件中的另一个函数获得的两个变量(父ID和子ID)设置帖子自定义分类。 var的$ a和$ b
当我手动输入术语ID时 - 一切正常但当我尝试使用变量 - 设置术语ID时 - 它不起作用
在第一个代码段中获取ID的功能,并尝试将条款保存在第二个代码段中。
//***IF YOU HAVE MODEL GET THE ID
if(!empty($auto_model)){
$auto_model_id = get_term_by( 'slug', $auto_model, $this->tax );
$auto_model_id = $auto_model_id->term_id;
} // end get model id
if ($auto_make_id !== null && $auto_model_id !== null) { // +++++ IF YOU HAVE BOTH
$this->p_id = $auto_make_id; // define variable
$this->c_id = $auto_model_id; // define variable
// set post with both these terms - jump to set post and pass ids to set post
//return $p_id;
return $c_id . $p_id;
}
function cicb_do_things($post_id) { // use this as the final build up before sending to construct
global $auto_make,$auto_model;
$this->makemodel();
$a = $this->p_id;
$b = $this->c_id;
$tag = array( 45 ); // this is how wp wants me to do it; and when I do the wp_set object works great
var_dump ($tag);
echo '<br>';
$tag = array( $a ); // when I put in my variable which is the also 45 - the term does not work
wp_set_object_terms( $post_id, $tag, $this->tax );
}