函数原型:
wp_trash_post_comments( int|WP_Post|null $post = null ): mixed|void
移动文章评论到垃圾站。
参数说明:
$post,文章或文章ID,如果空,则默认使用全局 $post 指向的文章。
函数源码:
function wp_trash_post_comments( $post = null ) {
global $wpdb;
$post = get_post( $post );
if ( ! $post ) {
return;
}
$post_id = $post->ID;
do_action( 'trash_post_comments', $post_id );
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
if ( ! $comments ) {
return;
}
// Cache current status for each comment.
$statuses = array();
foreach ( $comments as $comment ) {
$statuses[ $comment->comment_ID ] = $comment->comment_approved;
}
add_post_meta( $post_id, '_wp_trash_meta_comments_status', $statuses );
// Set status for all comments to post-trashed.
$result = $wpdb->update( $wpdb->comments, array( 'comment_approved' => 'post-trashed' ), array( 'comment_post_ID' => $post_id ) );
clean_comment_cache( array_keys( $statuses ) );
do_action( 'trashed_post_comments', $post_id, $statuses );
return $result;
}
包含钩子:
do_action( 'trashed_post_comments', int $post_id, array $statuses )
do_action( 'trash_post_comments', int $post_id )
使用举例:
wp_trash_post_comments(1);
删除文章ID为1的文章的评论。
-
WordPress函数:esc_html_x 带上下文的转义翻译WordPress函数:esc_html_x 带上下文的转义翻译
-
WordPress函数:esc_attr__ 转义属性及翻译WordPress函数:esc_attr__ 转义属性及翻译
-
WordPress函数:esc_attr_e 属性转义、翻译、显示WordPress函数:esc_attr_e 属性转义、翻译、显示
-
WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示WordPress函数:esc_attr_x 带上下文的转义属性,翻译显示
-
WP Multilang WordPress翻译插件WP Multilang插件的主要功能是提供多语言支持,使用户能够创建多语言版本的网站,满足不同语言用户的需求。
-
Post Type Switcher将 WordPress文章从一个类型转换到另一个类型Post Type Switcher是一个WordPress插件,用于将文章从一个类型转换到另一个类型,包括自定义文章类型。安装并启用该插件后,在编辑文章时,会在发布面板中增加Post Type选项,用户可以选择要转换到的文章类型并更新文章。此外,插件也支持在后台所有文章页面批量更改文章类型。
暂无评论,抢个沙发...