WordPress search causing database error
-
Hide Posts seems to be breaking the WordPress search and throwing a database error.
- WordPress 5.6.1
- WordPress Hide Posts 0.5.3
- PHP 7.4.9
- MySQL 5.7.33
A search for “help me” produces:
WordPress database error: [Not unique table/alias: 'wp_postmeta'] SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID FROM wp_posts LEFT JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_whp_hide_on_search' ) LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE 1=1 AND (((wp_posts.post_title LIKE '%help me%') OR (wp_postmeta.meta_value LIKE '%help me%') OR (wp_posts.post_excerpt LIKE '%help me%') OR (wp_posts.post_content LIKE '%help me%'))) AND (wp_posts.post_password = '') AND ( wp_postmeta.post_id IS NULL ) AND wp_posts.post_type IN ('post', 'page', 'attachment') AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_posts.post_title LIKE '%help me%' DESC, wp_posts.post_date DESC LIMIT 0, 12
(formatted this to make it a little more readable)
I can see the query has two left joins to the same table wp_postmeta without the use of table aliases, so MySQL is a little unhappy.
I’ve tried deactivating all other plugins and get the same result. I’ve also tried deactivating WordPress Hide Posts and my search results are returned correctly.
I only have the plugin enabled in my private Dev site at the moment, I can afford to have search not working in Prod but the same problem was occurring there as well.
Any suggestions what to try next? Any help appreciated!
Thanks
- The topic ‘WordPress search causing database error’ is closed to new replies.