简体   繁体   中英

Wordpress query for posts is pulling up revisions as results

I have the following wordpress query which is displaying the post title multiple times, I have checked and it's getting all the revisions for each post.

Here is the query:

SELECT DISTINCT post_title, ID 
FROM wpblog_posts 
WHERE post_title LIKE '%Kimberley%' 
OR post_title LIKE '%Camping%' 
AND wpblog_posts.post_type = 'post' 
AND post_status = 'publish' 
ORDER BY post_title DESC LIMIT 0, 6;

Anyone know why this might be happening.

Update

Removed from query string as not relevant and will make it easier to debug.

 LEFT JOIN wpblog_term_relationships rel ON rel.object_id = wpblog_posts.ID LEFT JOIN wpblog_term_taxonomy tax ON tax.term_taxonomy_id = rel.term_taxonomy_id LEFT JOIN wpblog_terms t ON t.term_id = tax.term_id 

Cheers

Check this query if it works for you:

SELECT DISTINCT post_title, ID 
FROM wpblog_posts 
WHERE (post_title LIKE '%Kimberley%' OR post_title LIKE '%Camping%')
AND wpblog_posts.post_type = 'post' 
AND post_status = 'publish' 
ORDER BY post_title DESC LIMIT 0, 6;

The query was looking for posts LIKE '%Kimberley%' - any type of post OR LIKE '%Camping%' AND wpblog_posts.post_type = 'post' ... .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM