我一直在尝试使用draft\\u to\\u publish&;new\\u to\\u publish
在发布特定类型(cpt)的帖子时创建更新。。。
它可以工作,但发布了600多次,而不是一次!
So... my question is
为什么会发生这种情况;如何验证它只发布一次(我花了10分钟删除)
here is code i currently have:
add_action(\'new_to_publish\', \'new_webnews_published\');
add_action(\'draft_to_publish\', \'new_webnews_published\');
function new_webnews_published($post_id){
$postData = get_post($post_id);
$post_id = $post_id;
$postData = get_post($post_id);
$postType = get_post_type($post_id);
$postTitle = $postData->post_title;
if($postType == \'webnews\') {
// LINK TO WEBNEWS PAGE
$webnewsPage = of_get_option(THEME_NAME.\'_webnews_select_page\');
// PREPARE UPDATE DATA
$update_title = __(\'News\',THEME_NAME);
$update_content = $postTitle;
$update_url = \'index.php?p=\'.$webnewsPage;
$post = array(
\'post_title\' => $update_title,
\'post_status\' => \'publish\',
\'post_type\' => \'miniupdate\'
);
$updatedid = wp_insert_post($post, 10, 1);
// Do the wp_insert_post action to insert it
do_action(\'wp_insert_post\', \'wp_insert_post\', 10, 1);
update_post_meta($updatedid, THEME_PREF.\'miniupdates_content\', $update_content);
update_post_meta($updatedid, THEME_PREF.\'miniupdates_link\', $update_url);
}
}
Last Thing:我想测试变量,例如:“echo‘something’;
我想我需要创建第二个函数并附加到admin\\u init<但是这里的时间限制是什么?我是否应该在“初稿到发布”挂钩中添加一些内容?