Title: Apparent bug when running exclude operations
Last modified: August 30, 2016

---

# Apparent bug when running exclude operations

 *  Resolved [minervaweb](https://wordpress.org/support/users/minervaweb/)
 * (@minervaweb)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/)
 * Hi there, I believe I’ve found a bug:
    I’ve set up a list view using your “Exclude”
   field to exclude all users that have a meta_value of ‘Y’ for a given meta_key.
   But what actually happens is that the list excludes all users where meta_key 
   == ‘Y’, and also all users where meta_key is undefined – that is, users who do
   not have an associated record for that meta_key in the wp_usermeta table.
 * I’ve tried using exclusion on several other fields, and it behaves the same way.
 * For now, I’m working around this by writing a hook that sets a default value 
   for this field everytime a user is created, and it seems to be working fine. 
   However, I’ve got almost 5000 users, so I’d rather not have all those empty meta
   keys slowing down the database if I don’t need them.
 * Love to hear your thoughts,
    thanks!
 * [https://wordpress.org/plugins/amr-users/](https://wordpress.org/plugins/amr-users/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/#post-6415172)
 * Hi – I’ll look into it. In meanwhile if you don’t have to many non-Y values, 
   you could go with a ‘include’ rather – eg: just include A,B,C,N rather than excluding‘
   Y’
 *  Plugin Author [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/#post-6415179)
 * HI
 * I cannot recreate the behaviour you describe – If I exclude a value it does NOT
   exclude the blanks as well UNLESS I tick ‘exclude if blank’.
 * Also in the second half of your post you say you ‘don’t’ want those records –
   perhaps you did tick ‘exclude if blank’.
 * Please double check your settings and advise any other info.
 *  Plugin Author [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/#post-6415192)
 * hmm – spooky – after hours of playing with something else now I may have managed
   to create this – weird – looking further.
 *  Plugin Author [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/#post-6415194)
 * Tell me the fields that this is happening with – how are they created?
    (what
   plugin and where stored)
 *  Plugin Author [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/#post-6415196)
 * Ok – it depends how the fields stored.
    PLugin uses wp meta query `… array (size
   =3) ‘key’ => string ‘Boolean’ (length=7) ‘value’ => string ‘Y’ (length=1) ‘compare’
   => string ‘!=’ (length=2)`
 * and yes the wp query will then only fetch records that HAVE a meta value and 
   that meta value is NOT the ‘excluded’ one. WP generally creates a meta record
   even when the value is a default/no value. So normal wp fields usually will cope
   fine because they will have a meta record. For non standrad wp meta usage, the
   plugin has to fetch the whole set anyway (eg: S2 member type array meta values)
   and then weed out the records to be excluded so behaviour can look different.
 * SO… for you
    either ensure every user has a meta record for the meta key you 
   are using so you can show the users who don’t have the excluded value OR see 
   in settings the ‘own query’ option – it will be reenabled in 3.20 just uploaded.
   Hard to say which will be more ‘efficient’ – it kinda depends on the data being
   queried and what selections there are. Let me know how you go.
 *  Plugin Author [anmari](https://wordpress.org/support/users/anmari/)
 * (@anmari)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/#post-6415223)
 * Just to be clear – the own query option fetches all the necessary meta records
   and then excludes users based on the include/exclude settings. So it copes with
   missing meta records (won’t exclude a user just because it doesn’t have the meta
   record). The downside of course is that it has to select more users to start.
   However it only selects the meta records it needs.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Apparent bug when running exclude operations’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amr-users_f6f6f4.svg)
 * [amr users](https://wordpress.org/plugins/amr-users/)
 * [Support Threads](https://wordpress.org/support/plugin/amr-users/)
 * [Active Topics](https://wordpress.org/support/plugin/amr-users/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amr-users/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amr-users/reviews/)

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)

 * 6 replies
 * 2 participants
 * Last reply from: [anmari](https://wordpress.org/support/users/anmari/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/apparent-bug-when-running-exclude-operations/#post-6415223)
 * Status: resolved