仅删除单个帖子的帖子修订

时间:2020-12-30 作者:programings

如何使用SQL查询仅删除由ID标识的特定帖子的帖子修订?

1 个回复
最合适的回答,由SO网友:KodimWeb 整理而成

如果需要SQL查询,那么此选项应该合适

function src_flush_revisions () {

    global $wpdb;
    $post_id = 5//exp post id

    if ( isset( $timeLimit ) ) {
        $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = \'revision\' AND `post_parent` = %d", $post_id ) );

        foreach ( $revision_ids as $revision_id ) {
            wp_delete_post_revision( $revision_id );
        }
    }
}
add_action( \'admin_init\', \'src_flush_revisions\' );

相关推荐

自定义“The_Posts_Pagination”并将列表放入div

Hello everybody, 我需要有关自定义wordpress分页的帮助。我想得到这个:这就是我所做的:在函数中。php,我添加了以下代码:function wp_custom_pagination($args = [], $class = \'pagination\') { if ($GLOBALS[\'wp_query\']->max_num_pages <= 1) return; $args = wp_parse_args( $args,