用于恢复wordpress中所有帖子的最新版本的SQL查询
我的wordpress网站最近遭到攻击,所有帖子似乎都被更新为空白版本。所以我想恢复所有帖子的最新版本。(注意:在wordpress中,当前发布的版本也作为修订版存储在数据库中。因此我认为我需要恢复第二个修订版(按降序排列)) 对此,SQL查询是什么用于恢复wordpress中所有帖子的最新版本的SQL查询,sql,wordpress,Sql,Wordpress,我的wordpress网站最近遭到攻击,所有帖子似乎都被更新为空白版本。所以我想恢复所有帖子的最新版本。(注意:在wordpress中,当前发布的版本也作为修订版存储在数据库中。因此我认为我需要恢复第二个修订版(按降序排列)) 对此,SQL查询是什么 任何帮助都将不胜感激 所以,您所需要的只是在数据库中(幸运的是)。帖子本身可以这样检索 global $wpdb; $query = "SELECT * FROM wp_posts WHERE post_type = 'revision'";
任何帮助都将不胜感激 所以,您所需要的只是在数据库中(幸运的是)。帖子本身可以这样检索
global $wpdb;
$query = "SELECT * FROM wp_posts WHERE post_type = 'revision'";
$query_results = $wpdb->get_results($query, ARRAY_A);
foreach ($query_results as $q_key => $q_value) {
$post = array(
'post_content' => $q_value['post_content']
'post_name' => $q_value['post_name']
'post_title' => $q_value['post_title']
'post_status' => $q_value['post_status']
'post_type' => 'post'
'post_author' => $q_value['post_author']
'ping_status' => $q_value['ping_status']
'post_parent' => $q_value['post_parent']
'menu_order' => $q_value['menu_order']
'to_ping' => $q_value['to_ping']
'pinged' => $q_value['pinged']
'post_password' => $q_value['post_password']
'guid' => $q_value['guid']
'post_content_filtered' => $q_value['post_content_filtered']
'post_excerpt' => $q_value['post_excerpt']
'post_date' => $q_value['post_date']
'post_date_gmt' => $q_value['post_date_gmt']
'comment_status' => $q_value['comment_status']
);
wp_insert_post( $post );
}
在这里阅读
现在,取决于你有多少帖子,这可能需要一段时间,也可能会中断。如果它坏了,那么您需要将它包装到一个用AJAX调用的函数中。像这样的事情应该可以做到:
add_action( 'wp_ajax_insert_posts', 'database_ajax_insert_posts' );
add_action( 'wp_ajax_nopriv_insert_posts', 'database_ajax_insert_posts' );
function database_ajax_insert_posts(){
global $wpdb;
$offset = $_POST['offset'];
$query = "SELECT * FROM wp_posts WHERE post_type = 'revision' LIMIT $offset, 1";
$query_results = $wpdb->get_results($query, ARRAY_A);
foreach ($query_results as $q_key => $q_value) {
$post = array(
'post_content' => $q_value['post_content']
'post_name' => $q_value['post_name']
'post_title' => $q_value['post_title']
'post_status' => $q_value['post_status']
'post_type' => 'post'
'post_author' => $q_value['post_author']
'ping_status' => $q_value['ping_status']
'post_parent' => $q_value['post_parent']
'menu_order' => $q_value['menu_order']
'to_ping' => $q_value['to_ping']
'pinged' => $q_value['pinged']
'post_password' => $q_value['post_password']
'guid' => $q_value['guid']
'post_content_filtered' => $q_value['post_content_filtered']
'post_excerpt' => $q_value['post_excerpt']
'post_date' => $q_value['post_date']
'post_date_gmt' => $q_value['post_date_gmt']
'comment_status' => $q_value['comment_status']
);
wp_insert_post( $post );
}
}
还有阿贾克斯
jQuery(document).ready(function($) {
"use strict";
var offset = 1;
function ajax_call(){
$.ajax({
type: "POST",
url: ajaxurl,
data: {
'action': 'insert_posts',
'offset': offset,
},
success: function(response) {
if (offset < 100){ //Number of posts go here
offset += 1;
ajax_call();
} else{
$('#wpbody-content').append('<p>All done!</p>' );
}
},
error : function (jqXHR, textStatus, errorThrown) {
$('#wpbody-content').html(jqXHR + ' :: ' + textStatus + ' :: ' + errorThrown);
}
});
}
ajax_call();
});
分类法应该在数据库中,您可以以类似的方式获取它们
这不是万无一失的,但应该有效。我能看到的一点可能有点问题,那就是为这篇文章找到正确的分类法,但这是可行的,尽管有点麻烦
希望这有帮助
wp_localize_script('your_handle', 'db_from_WP', array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
));