_update_posts_count_on_transition_post_status

函数
_update_posts_count_on_transition_post_status ( $new_status, $old_status, $post = null )
参数
  • (string) $new_status The status the post is changing to.
    Required:
  • (string) $old_status The status the post is changing from.
    Required:
  • (WP_Post) $post Post object
    Required:
    Default: null
定义位置
相关方法
_update_term_count_on_transition_post_statuswp_transition_post_status_transition_post_statusblock_core_calendar_update_has_published_post_on_transition_post_status_update_posts_count_on_delete
引入
4.0.0
弃用
-

_update_posts_count_on_transition_post_status: 当一个文章从一个状态过渡到另一个状态时,该函数更新特定术语的文章计数: 当文章被添加、删除或修改时,它被用来确保文章计数的准确性。

当一个文章的状态发生变化时,用于更新当前网站的文章数量的处理程序。

function _update_posts_count_on_transition_post_status( $new_status, $old_status, $post = null ) {
	if ( $new_status === $old_status ) {
		return;
	}

	if ( 'post' !== get_post_type( $post ) ) {
		return;
	}

	if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
		return;
	}

	update_posts_count();
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-07 06:33:36

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: