Title: Bug on query
Last modified: October 9, 2018

---

# Bug on query

 *  [mfcanovas](https://wordpress.org/support/users/mfcanovas/)
 * (@mfcanovas)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/bug-on-query/)
 * I think you have a bug in your scan postmeta query.
 * This is the current query:
 *     ```
       SELECT meta_value FROM wp_postmeta
       			WHERE post_id = ?
       			AND meta_key = '_thumbnail_id' OR meta_key LIKE '%gallery%' OR meta_key LIKE '%ids%'
       ```
   
 * This query will fetch all rows matching post_id AND meta_key = ‘_thumbnail_id’.
   It will also fetch every row with meta_key like gallery or ids without taking
   into account the specified post_id.
 * I think the correct query will look like this:
 *     ```
       SELECT meta_value FROM wp_postmeta
       			WHERE post_id = ?
       			AND (meta_key = '_thumbnail_id' OR meta_key LIKE '%gallery%' OR meta_key LIKE '%ids%')
       ```
   

The topic ‘Bug on query’ is closed to new replies.

 * ![](https://ps.w.org/media-cleaner/assets/icon-256x256.png?rev=2791576)
 * [Media Cleaner: Clean your WordPress!](https://wordpress.org/plugins/media-cleaner/)
 * [Support Threads](https://wordpress.org/support/plugin/media-cleaner/)
 * [Active Topics](https://wordpress.org/support/plugin/media-cleaner/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-cleaner/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-cleaner/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [mfcanovas](https://wordpress.org/support/users/mfcanovas/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/bug-on-query/)
 * Status: not resolved