Code test

-- 1. Insert posts
INSERT INTO wp_posts (
    post_author,          -- change to your WP user ID (usually 1)
    post_date, post_date_gmt,
    post_content,
    post_title,
    post_excerpt,
    post_status,
    comment_status,
    ping_status,
    post_name,
    post_modified, post_modified_gmt,
    post_type,
    comment_count,
    guid
)
SELECT
    1                                          AS post_author,
    p.DateCreated                              AS post_date,
    UTC_TIMESTAMP()                            AS post_date_gmt,   -- or convert properly if you want
    p.PostContent                              AS post_content,
    p.Title                                    AS post_title,
    ''                                         AS post_excerpt,
    IF(p.IsPublished, 'publish', 'draft')      AS post_status,
    IF(p.HasCommentsAllowed, 'open', 'closed') AS comment_status,
    'open'                                     AS ping_status,
    COALESCE(NULLIF(p.Slug,''), LOWER(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(p.Title),' ','-'),'---','-'),'--','-'),'.',''))) AS post_name,
    p.DateModified                             AS post_modified,
    p.DateModified                             AS post_modified_gmt,
    'post'                                     AS post_type,
    (SELECT COUNT(*) FROM be_Comments c WHERE c.PostId = p.PostId AND c.IsPublished = 1 AND c.IsDeleted = 0) AS comment_count,
    CONCAT('https://blog.digitaltools.com/?p=', wp_posts.ID)  -- will be fixed in step 3
FROM be_Posts p
WHERE p.IsPublished = 1
ORDER BY p.DateCreated;
      -- 1. Insert posts
INSERT INTO wp_posts (
    post_author,          -- change to your WP user ID (usually 1)
    post_date, post_date_gmt,
    post_content,
    post_title,
    post_excerpt,
    post_status,
    comment_status,
    ping_status,
    post_name,
    post_modified, post_modified_gmt,
    post_type,
    comment_count,
    guid
)
SELECT
    1                                          AS post_author,
    p.DateCreated                              AS post_date,
    UTC_TIMESTAMP()                            AS post_date_gmt,   -- or convert properly if you want
    p.PostContent                              AS post_content,
    p.Title                                    AS post_title,
    ''                                         AS post_excerpt,
    IF(p.IsPublished, 'publish', 'draft')      AS post_status,
    IF(p.HasCommentsAllowed, 'open', 'closed') AS comment_status,
    'open'                                     AS ping_status,
    COALESCE(NULLIF(p.Slug,''), LOWER(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(p.Title),' ','-'),'---','-'),'--','-'),'.',''))) AS post_name,
    p.DateModified                             AS post_modified,
    p.DateModified                             AS post_modified_gmt,
    'post'                                     AS post_type,
    (SELECT COUNT(*) FROM be_Comments c WHERE c.PostId = p.PostId AND c.IsPublished = 1 AND c.IsDeleted = 0) AS comment_count,
    CONCAT('https://blog.digitaltools.com/?p=', wp_posts.ID)  -- will be fixed in step 3
FROM be_Posts p
WHERE p.IsPublished = 1
ORDER BY p.DateCreated;

    
-- 1. Insert posts
INSERT INTO wp_posts (
    post_author,          -- change to your WP user ID (usually 1)
    post_date, post_date_gmt,
    post_content,
    post_title,
    post_excerpt,
    post_status,
    comment_status,
    ping_status,
    post_name,
    post_modified, post_modified_gmt,
    post_type,
    comment_count,
    guid
)
SELECT
    1                                          AS post_author,
    p.DateCreated                              AS post_date,
    UTC_TIMESTAMP()                            AS post_date_gmt,   -- or convert properly if you want
    p.PostContent                              AS post_content,
    p.Title                                    AS post_title,
    ''                                         AS post_excerpt,
    IF(p.IsPublished, 'publish', 'draft')      AS post_status,
    IF(p.HasCommentsAllowed, 'open', 'closed') AS comment_status,
    'open'                                     AS ping_status,
    COALESCE(NULLIF(p.Slug,''), LOWER(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(p.Title),' ','-'),'---','-'),'--','-'),'.',''))) AS post_name,
    p.DateModified                             AS post_modified,
    p.DateModified                             AS post_modified_gmt,
    'post'                                     AS post_type,
    (SELECT COUNT(*) FROM be_Comments c WHERE c.PostId = p.PostId AND c.IsPublished = 1 AND c.IsDeleted = 0) AS comment_count,
    CONCAT('https://blog.digitaltools.com/?p=', wp_posts.ID)  -- will be fixed in step 3
FROM be_Posts p
WHERE p.IsPublished = 1
ORDER BY p.DateCreated;

Code test over.

Leave a Comment

Your email address will not be published. Required fields are marked *