Plugins with element criteria selection does not work for empty or zero values I made a plugin which count the number of users per groups defined by the field accent which is a text field and can be empty or contain numbers from 0 to 12.

public function actionCountUsers() {

    // Delete all the entry caches
    craft()-&gt;templateCache-&gt;deleteCachesByElementType('User');

    // Now find the entry IDs
    $criteria = craft()-&gt;elements-&gt;getCriteria('User', array('group' =&gt; 'unepMembers', 'limit' =&gt; null, 'status' =&gt; null, 'localeEnabled' =&gt; null));
    $criteria-&gt;group = 'unepMembers';
    $criteria-&gt;limit = null;
    $criteria-&gt;status = null;
    $criteria-&gt;localeEnabled = null;

    //
    $totalEntries = $criteria-&gt;total();
    UnepPlugin::log($totalEntries.' USERS (no criteria)', LogLevel::Warning);

    //
    $criteria-&gt;accent = '';
    $totalEntries = $criteria-&gt;total();
    UnepPlugin::log($totalEntries.' USERS with empty accent', LogLevel::Warning);

    //
    $totalUsers = 0;
    for ($i = 0; $i &lt;= 15; $i++) {
        $criteria-&gt;accent = $i;
        $totalEntries = $criteria-&gt;total();
        MigPlugin::log($totalEntries.' USERS with accent :'.$criteria-&gt;accent, LogLevel::Warning);

        $totalUsers = $totalUsers + $totalEntries;
    }
    MigPlugin::log($totalUsers.' USERS with accents', LogLevel::Warning);

}


As you can see the result here below there is a problem with a criteria values empty or 0 on the accent field: they just do not work and count the total number of users.

***********************
2015/10/11 07:09:48 [warning] [plugin] 3109 USERS (no criteria)  
2015/10/11 07:09:48 [warning] [plugin] 3109 USERS with empty accent  
2015/10/11 07:14:01 [warning] [plugin] 3109 USERS with accent :0  
2015/10/11 07:09:48 [warning] [plugin] 1849 USERS with accent :1  
2015/10/11 07:09:48 [warning] [plugin] 501 USERS with accent :2  
2015/10/11 07:09:48 [warning] [plugin] 0 USERS with accent :3  
2015/10/11 07:09:48 [warning] [plugin] 72 USERS with accent :4  
2015/10/11 07:09:49 [warning] [plugin] 8 USERS with accent :5  
2015/10/11 07:09:49 [warning] [plugin] 1 USERS with accent :6  
2015/10/11 07:09:49 [warning] [plugin] 0 USERS with accent :7  
2015/10/11 07:09:49 [warning] [plugin] 4 USERS with accent :8  
2015/10/11 07:09:49 [warning] [plugin] 81 USERS with accent :9  
2015/10/11 07:09:49 [warning] [plugin] 232 USERS with accent :10  
2015/10/11 07:09:49 [warning] [plugin] 246 USERS with accent :11  
2015/10/11 07:09:49 [warning] [plugin] 115 USERS with accent :12  
2015/10/11 07:09:49 [warning] [plugin] 0 USERS with accent :13  
2015/10/11 07:09:49 [warning] [plugin] 0 USERS with accent :14  
2015/10/11 07:09:49 [warning] [plugin] 0 USERS with accent :15  
2015/10/11 07:09:49 [warning] [plugin] 3109 USERS with accents  


Craft bug or did I miss something in my code?
When you do this:



$criteria-&gt;accent = '';


Craft is going to look for users where the accent field’s DB cell is an empty string.

Those values are probably null though, if they aren’t getting returned.

Try setting your accent param to :empty: instead of ''. When you do that, Craft will search for both empty strings and null values, so you should get the results you’re expecting.