Skip to content

Instantly share code, notes, and snippets.

@maicong
Created February 19, 2016 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maicong/4bad738e7a3387fc8e21 to your computer and use it in GitHub Desktop.
Save maicong/4bad738e7a3387fc8e21 to your computer and use it in GitHub Desktop.
提取 WP 文章数据库信息
SELECT
unix_timestamp(p.post_date) AS created,
p.post_content AS text,
p.post_title AS title,
p.post_name AS slug,
m.thumbnail
FROM
wp_posts AS p
LEFT JOIN (
SELECT
m2.post_id AS post_id,
m1.meta_value AS thumbnail
FROM
wp_postmeta AS m1
JOIN (
SELECT
wp_postmeta.post_id AS post_id,
wp_postmeta.meta_value AS thumbnail_id
FROM
wp_postmeta
WHERE
wp_postmeta.meta_key = '_thumbnail_id'
) AS m2 ON m1.post_id = m2.thumbnail_id
WHERE
m1.meta_key = '_wp_attached_file'
) AS m ON p.ID = m.post_id
WHERE
p.post_author = 1
AND p.post_status = 'publish'
AND p.post_type = 'post'
ORDER BY
p.ID ASC
@maicong
Copy link
Author

maicong commented Apr 15, 2016

SELECT
    np.pid AS pid,
    ocm.comment_ID AS cmid,
    ocm.user_id AS uid,
    ocm.comment_author AS author,
    ocm.comment_author_email AS email,
    ocm.comment_author_url AS url,
    ocm.comment_author_IP AS IP,
    ocm.comment_date AS created,
    ocm.comment_content AS content,
    ocm.comment_approved AS STATUS,
    ocm.comment_agent AS userAgent,
    ocm.comment_parent AS parentID,
    ocm.comment_mail_notify AS mailNotify
FROM
    mc_posts AS np
INNER JOIN wp_posts AS op ON np.title = op.post_title
JOIN wp_comments AS ocm ON ocm.comment_post_ID = op.ID
WHERE
    op.post_status = 'publish'
AND op.post_type = 'post'
ORDER BY
    op.ID ASC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment