<p>Here's what's actually happening with this line of code...</p>

<pre><code>$criteria-&gt;creditsUsed &gt; 0;
</code></pre>

<p>You are actually generating the <strong>boolean</strong> value of "is creditsUsed more than zero". Granted, you aren't setting it to an actual variable, but nonetheless you are generating a boolean value. For example:</p>

<pre><code>$moreThanZeroCreditsUsed = ($criteria-&gt;creditsUsed &gt; 0);
</code></pre>

<p>Even though you're not assigning that new boolean value to a variable, it's still valid PHP (and therefore no error is thrown).</p>

<p>What it looks like you are trying to do instead is to actually set the value of <code>creditsUsed</code>, which you'd need to use an <strong>equals sign</strong> to do:</p>

<pre><code>$criteria-&gt;creditsUsed = "whatever";
</code></pre>

<p>If my memory serves me correctly, the way to denote a comparison on an ElementCriteriaModel is to simply pass the comparison as a string:</p>

<pre><code>$criteria-&gt;creditsUsed = "&gt; 0";
</code></pre>

<p>See the last example in <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#parameter-value-syntax" rel="nofollow">this subsection...</a> Granted, it's being applied via Twig syntax, but it's still modifying the ElementCriteriaModel in the same way:</p>

<pre><code>craft.entries.width('&gt;= 100')
</code></pre>

CC BY-SA 3.0
2014-10-11T20:48:46.670Z
2014-10-11T20:48:46.670Z
Lindsey D
<p>Can anyone tell me why this is returning all entries instead of entries with a <code>creditsUsed</code> field > 0? <code>creditsUsed</code> is a number field that I created for this entry type.</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;authorId = craft()-&gt;userSession-&gt;getUser()-&gt;id;
$criteria-&gt;section = 'news';
$criteria-&gt;creditsUsed &gt; 0;
$criteria-&gt;status = null;
$entries = $criteria-&gt;total();
</code></pre>

<plugin-development><elementcriteriamodel>
Modify an ElementCriteriaModel to compare against numeric field
# Modify an ElementCriteriaModel to compare against numeric field

(Asked by: username_0 on 2014-10-11)

Can anyone tell me why this is returning all entries instead of entries with a creditsUsed field > 0? creditsUsed is a number field that I created for this entry type.
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->authorId = craft()->userSession->getUser()->id;
$criteria->section = 'news';
$criteria->creditsUsed > 0;
$criteria->status = null;
$entries = $criteria->total();

**Tags:** plugin-development, elementcriteriamodel


---

## 1 answers

### Answer by username_1 on 2014-10-11. Score: 3 | Accepted answer

Here's what's actually happening with this line of code...
$criteria->creditsUsed > 0;

You are actually generating the boolean value of "is creditsUsed more than zero". Granted, you aren't setting it to an actual variable, but nonetheless you are generating a boolean value. For example:
$moreThanZeroCreditsUsed = ($criteria->creditsUsed > 0);

Even though you're not assigning that new boolean value to a variable, it's still valid PHP (and therefore no error is thrown).
What it looks like you are trying to do instead is to actually set the value of creditsUsed, which you'd need to use an equals sign to do:
$criteria->creditsUsed = "whatever";

If my memory serves me correctly, the way to denote a comparison on an ElementCriteriaModel is to simply pass the comparison as a string:
$criteria->creditsUsed = "> 0";

See the last example in this subsection... Granted, it's being applied via Twig syntax, but it's still modifying the ElementCriteriaModel in the same way:
craft.entries.width('>= 100')


---

