[英]How to delete posts without featured images in wordpress via mysql?
[英]WordPress posts with featured images and categories
我正在寻找以下解决方案:
SELECT ID
, post_date_gmt
, post_content
, post_title
, post_modified_gmt
FROM wphj_posts
WHERE post_status = 'publish'
和:
SELECT DISTINCT meta_value
, post_id
, meta_id
FROM wphj_postmeta
WHERE meta_key LIKE '_wp_attached_file'
ORDER
BY meta_value ASC
我首先要做的是,它不起作用,因为我想要它:
SELECT ID
, post_date_gmt
, post_content
, post_title
, post_modified_gmt
, meta_value
FROM wphj_posts
, wphj_postmeta
WHERE post_status = 'publish'
AND meta_key LIKE '_wp_attached_file'
我只是尝试查询WordPress数据库以从wp_posts
获取帖子数据,并从wp_postmeta
表中获取同一帖子的特色图片。
我尝试做的事情:使用union,unionall,join,inner join,left join。 不幸的是,它们不起作用。
更新,使用wpDatatables插件提出,可在插件仪表板上使用,但不能单独作为查询使用:\\-我在做错什么呢?
SELECT posts_post.ID AS post_ID,
posts_post.post_date_gmt AS post_post_date_gmt,
posts_post.post_title AS post_post_title,
CONCAT('<a href="',posts_post.guid,'">',posts_post.post_title,'</a>') AS post_title_with_link_to_post,
posts_post.post_content AS post_post_content,
posts_post.post_status AS post_post_status,
posts_post.post_name AS post_post_name,
CONCAT(
'<a href="',
posts_post.guid,
'"><img src="',
REPLACE(
posts_post_img.guid,
CONCAT(
'.',
SUBSTRING_INDEX(
posts_post_img.guid,
'.',
-1
)
),
CONCAT(
'-150x150.' ,
SUBSTRING_INDEX(
posts_post_img.guid,
'.',
-1
)
)
),
'" /></a>'
) AS post_thumbnail_with_link_to_post,
post_taxonomy_category_tbl.name AS post_taxonomy_category
FROM wphj_posts AS posts_post
INNER JOIN (SELECT name, object_id as id FROM wphj_terms AS post_taxonomy_category_tbl_terms INNER JOIN wphj_term_taxonomy AS post_taxonomy_category_tbl_termtaxonomy ON post_taxonomy_category_tbl_termtaxonomy.term_id = post_taxonomy_category_tbl_terms.term_id AND post_taxonomy_category_tbl_termtaxonomy.taxonomy = 'category' INNER JOIN wphj_term_relationships AS rel_post_taxonomy_category_tbl ON post_taxonomy_category_tbl_termtaxonomy.term_taxonomy_id = rel_post_taxonomy_category_tbl.term_taxonomy_id) AS post_taxonomy_category_tbl
ON post_taxonomy_category_tbl.ID = posts_post.id
LEFT JOIN (SELECT posts_post_imgposts.guid AS guid, posts_post_imgpostmeta.post_id AS post_id
FROM wphj_postmeta AS posts_post_imgpostmeta
INNER JOIN wphj_posts AS posts_post_imgposts
ON posts_post_imgpostmeta.meta_value = posts_post_imgposts.ID
WHERE posts_post_imgpostmeta.meta_key = '_thumbnail_id' ) AS posts_post_img
ON posts_post_img.post_id = posts_post.ID
WHERE 1=1
AND posts_post.post_type = 'post'
您可以尝试使用此代码,我在本地安装程序上以sequal pro运行它,并且我认为它可以工作,因此我认为它可以工作。
SELECT ID,
post_date_gmt,
post_content,
post_title,
post_modified_gmt,
meta_value
FROM wphj_posts, wphj_postmeta
WHERE wphj_posts.ID = wphj_postmeta.post_id
AND wphj_postmeta.meta_key = '_wp_attached_file'
AND wphj_posts.post_status = 'publish'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.