开发者

List all duplicate posts through mySQL

开发者 https://www.devze.com 2023-03-01 08:09 出处:网络
How can I list all posts that are in wp_posts and have the same pos开发者_如何学Ct_title?Taking into account BrokenCrust\'s comment

How can I list all posts that are in wp_posts and have the same pos开发者_如何学Ct_title?


Taking into account BrokenCrust's comment

Assuming that wp_posts is from WordPress, it may also contain post revisions and pages or menus (and now custom types) that have the same post_title but that are not duplicate posts.

SELECT p1.* FROM wp_post p1 
INNER JOIN wp_post p2 ON (p1.id <> p2.id 
                      AND p1.post_title = p2.post_title
                      AND p1.revisions = p2.revisions
                      AND p1.page = p2.page)

If you don't want to see repeats in your list do

SELECT DISTINCT p1.post_title FROM wp_post p1 
INNER JOIN wp_post p2 ON (p1.id <> p2.id AND p1.post_title = p2.post_title)


SELECT * FROM wp_posts p 
WHERE (SELECT COUNT(*) FROM wp_posts WHERE post_title = p.post_title) > 1
0

精彩评论

暂无评论...
验证码 换一张
取 消