• Resolved minervaweb

    (@minervaweb)


    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/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author anmari

    (@anmari)

    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

    (@anmari)

    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

    (@anmari)

    hmm – spooky – after hours of playing with something else now I may have managed to create this – weird – looking further.

    Plugin Author anmari

    (@anmari)

    Tell me the fields that this is happening with – how are they created?
    (what plugin and where stored)

    Plugin Author anmari

    (@anmari)

    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

    (@anmari)

    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.