Wordpress query for posts is pulling up revisions

2019-08-21 11:52发布

问题:

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

回答1:

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' ....