【发布时间】:2015-03-09 20:46:12
【问题描述】:
尝试通过添加操作(保存帖子)挂钩为帖子设置自定义分类术语
这是我的代码
function dosomething(){
global $post, $wpdb;
$id = $post->ID;
global $id; // using id somewhere else
$cat_ids = array( 45,35 ); // will be vars at somepoint in the future
wp_set_post_terms( $id , $cat_ids, 'OriginalTag');
}
add_action('save_post', 'dosomething',10); // this will run the function on page load
这对我不起作用?但是通过反复试验我发现,如果我将 set_post_terms 函数中的 $id 替换为帖子的实际值,如下所示:
wp_set_post_terms( 2154 , $cat_ids, 'OriginalTag'); //2154 being the post ID
一切正常......:/无法弄清楚我在这里做错了什么
附言我已经回显了 $id 并且它确实返回了正确的值
【问题讨论】:
标签: wordpress function variables