Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress设置发布条件并-添加操作-保存发布问题_Wordpress_Function_Variables - Fatal编程技术网

WordPress设置发布条件并-添加操作-保存发布问题

WordPress设置发布条件并-添加操作-保存发布问题,wordpress,function,variables,Wordpress,Function,Variables,试图通过addactionsavepost钩子为帖子设置自定义分类术语 这是我的密码 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

试图通过addactionsavepost钩子为帖子设置自定义分类术语

这是我的密码

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替换为post的实际值,如下所示:

wp_set_post_terms( 2154 , $cat_ids, 'OriginalTag'); //2154 being the post ID
一切正常…:/我想不出我做错了什么

p、 我回显了$id,它确实返回了正确的值

function dosomething($id){
    $cat_ids = array( 290, 44 ); // will be vars at somepoint in the future
    wp_set_post_terms( $id , $cat_ids, 'post_tag');
}

add_action('save_post', 'dosomething', 10, 1); // this will run the function on page load
这对我来说很有效,显然我已经替换了我自己的标记ID,并使用了默认的分类法,所以将您自己的标记ID放回去。我通过行动电话传递新帖子的$id,而不是globals,这对我也不起作用