我建议post status transitions 仅在满足设置的条件时运行。
Example:
add_action( \'transition_post_status\', \'add_awesome_terms\', 10, 3 );
function add_awesome_terms( $new_status, $old_status, $post ) {
// only run when it\'s a page, new status is publish and old status isn\'t publish
if ( $post->post_type == \'page\' && $new_status == \'publish\' && $old_status != \'publish\' ) {
// do whatever you need here, it runs only when your set conditions are met
wp_insert_term( $post->post_title, \'mypages\' );
}
}
小奖励:你已经有了一个
$post 对象,您可以访问
$post 变量。
您可能想添加自己的条件,使其防弹。当前每次新状态为publish 而老年人不是publish. 这完全取决于页面/帖子管理的设置方式。
可能的岗位状态:
new – 没有以前的状态时publish – 已发布的帖子或页面pending – 待审核的帖子draft – 处于草稿状态的帖子auto-draft – 新创建的无内容帖子future – 计划在将来发布的帖子private – 未登录的用户不可见inherit – 修订或附件trash – 帖子已被丢弃,请不要忘记使用$post 变量对您有利,您已经拥有了!列出了变量here.