Last active
December 28, 2019 04:45
-
-
Save tranquangchau/c660d715d42e8516e2f3e4b3b7ef7b04 to your computer and use it in GitHub Desktop.
wordpress wp, export datbase post wp_postmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = "localhost"; | |
$username = "site_wp_bk_1812"; | |
$password = ""; | |
$dbname = "site_wp_bk_1812"; | |
// Create connection | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
$sql = "SELECT * FROM wp_posts Where ID >= 5383"; | |
//$sql = "SELECT * FROM wp_posts Where ID = 5391"; | |
$result = $conn->query($sql); | |
$insert=''; | |
while($row = mysqli_fetch_assoc($result)) { | |
$insert.="INSERT INTO wp_posts | |
(post_author, | |
post_date, | |
post_date_gmt, | |
post_content, | |
post_title, | |
post_excerpt, | |
post_status, | |
comment_status, | |
ping_status, | |
post_password, | |
post_name, | |
to_ping, | |
pinged, | |
post_modified, | |
post_modified_gmt, | |
post_content_filtered, | |
post_parent, | |
guid, | |
menu_order, | |
post_type, | |
post_mime_type, | |
comment_count | |
) | |
VALUES | |
"; | |
/* | |
$insert .= "( | |
'".addslashes($row['post_author'])."', | |
'".addslashes($row['post_date'])."', | |
'".addslashes($row['post_date_gmt'])."', | |
'".addslashes($row['post_content'])."', | |
'".addslashes($row['post_title'])."', | |
'".addslashes($row['post_excerpt'])."', | |
'".addslashes($row['post_status'])."', | |
'".addslashes($row['comment_status'])."', | |
'".addslashes($row['ping_status'])."', | |
'".addslashes($row['post_password'])."', | |
'".addslashes($row['post_name'])."', | |
'".addslashes($row['to_ping'])."', | |
'".addslashes($row['pinged'])."', | |
'".addslashes($row['post_modified'])."', | |
'".addslashes($row['post_modified_gmt'])."', | |
'".addslashes($row['post_content_filtered'])."', | |
'".addslashes($row['post_parent'])."', | |
'".addslashes($row['guid'])."', | |
'".addslashes($row['menu_order'])."', | |
'".addslashes($row['post_type'])."', | |
'".addslashes($row['post_mime_type'])."', | |
'".addslashes($row['comment_count'])."' | |
);"; | |
*/ | |
$id_at = $row['ID']; | |
unset($row['ID']); | |
$insert_vl= []; | |
foreach($row as $vl_at){ | |
$insert_vl[] = "'".addslashes($vl_at)."'"; | |
} | |
//echo '3<br>'; | |
$insert .= "(".implode(',',$insert_vl).");"; | |
$insert .='SET @last_id := LAST_INSERT_ID();'; | |
$sql = "SELECT * FROM wp_postmeta Where post_id = ".$id_at; | |
$result_sub = $conn->query($sql); | |
$temp =[]; | |
while($row = $result_sub->fetch_assoc()) { | |
$temp[] = "( | |
@last_id, | |
'".addslashes($row['meta_key'])."', | |
'".addslashes($row['meta_value'])."' | |
)"; | |
} | |
if($temp){ | |
$insert .="INSERT INTO wp_postmeta | |
(post_id, | |
meta_key, | |
meta_value | |
) | |
VALUES | |
"; | |
$temp_last = implode(",",$temp); | |
$insert .= $temp_last; | |
$insert .= ";"; | |
} | |
} | |
echo $insert; | |
$conn->close(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment