forked from corgus/eas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_home.php
66 lines (39 loc) · 1.48 KB
/
import_home.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
Template Name: Import Home
*/
include( ABSPATH . 'wp-admin/includes/image.php' );
echo '<!DOCTYPE html>';
$conn = new mysqli('localhost','emergentartspace','4BUcJ42csYKdy3Uz');
$result = $conn->query("
select ID, post_date, post_content, post_title, post_name from emergentartspace.wp_posts where post_type = 'post' and post_status = 'publish'
");
while ($p = $result->fetch_assoc()) {
$query = $wpdb->prepare('select * from wp_posts p where post_title = %s', $p['post_title']);
$equiv_post = $wpdb->get_row($query);
import_child_comments($conn, $p['ID'], $equiv_post->ID);
}
function import_comment($db, $old_id, $email, $date, $content, $newparent, $op) {
$new_user = get_user_by('email', $email);
$new_id = wp_insert_post(array(
'post_author' => $new_user->ID,
'post_date' => $date,
'post_content' => $content,
'post_type' => 'forum',
'post_parent' => $newparent,
'post_status' => 'publish'
));
_d($new_id);
eas_update_meta($new_id, 'op', $op);
import_child_comments($db, $old_id, $new_id, $op);
}
function import_child_comments($db, $parent, $newparent, $op = 0) {
if ($op == 0) $op = $newparent;
$query = "
select * from emergentartspace.wp_comments where comment_approved = 1 and comment_post_ID = ".$parent." or comment_parent = ".$parent."
";
$comm = $db->query($query);
while ($c = $comm->fetch_assoc()) {
import_comment($db, $c['comment_ID'], $c['comment_author_email'], $c['comment_date'], $c['comment_content'], $newparent, $op);
}
}