Answers.Body: <p>Found it: the reason for the Exception is, that the dynamic method <code>productStartDate</code> (coming from the CustomFieldBehavior) needs an Array as parameter.</p>
  <p>I have no clue why I get this misleading Exception though...</p>
  <p>So finally, this works:</p>
  <pre><code>use craft\commerce\elements\Product;
  $product = Product::find()
                  -&gt;type('ticket')
                  -&gt;productStartDate(['&gt;=&quot;2021-01-01 00:00:00&quot;'])
                  -&gt;all();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-29T14:28:30.107Z
Answers.LastActivityDate: 2021-01-29T14:35:41.107Z
Answers.LastEditDate: 2021-01-29T14:35:41.107Z
Answers.UserDisplayName: Matthias Redl-Mann
Body: <p>I'm on Craft 3.4.30 (latest 3.4) and Commerce 2.2.25 (latest 2.2):</p>
  <p>My product type &quot;ticket&quot; has a custom date field with handle <code>productStartDate</code>.</p>
  <p>E.g. the following query in TWIG works:</p>
  <pre><code>{% set products = craft.products().type('ticket').productStartDate('&gt;= 2021-01-01 00:00:00').all() %}
  </code></pre>
  <p>I get nice results including my custom field <code>productStartDate</code></p>
  <p>I am trying the same in a console command with PHP:</p>
  <pre><code>use craft\commerce\elements\Product;
  $product = Product::find()
                  -&gt;type('ticket')
                  -&gt;productStartDate('&gt;= 2021-01-01 00:00:00')
                  -&gt;all();
  </code></pre>
  <p>Gives me this Exception:</p>
  <pre><code>Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: craft\behaviors\CustomFieldBehavior::productStartDate()'
  
  in /myproject/vendor/yiisoft/yii2/base/BaseObject.php:222
  
  Stack trace:
  #0 /myproject/storage/runtime/compiled_classes/CustomFieldBehavior.php(542): yii\base\BaseObject-&gt;__call('productStartDat...', Array)
  #1 [internal function]: craft\behaviors\CustomFieldBehavior-&gt;__call('productStartDat...', Array)
  #2 /myproject/vendor/yiisoft/yii2/base/Component.php(297): call_user_func_array(Array, Array)
  #3 /myproject/vendor/craftcms/cms/src/elements/db/ElementQuery.php(548): yii\base\Component-&gt;__call('productStartDat...', Array)
  #4 /myproject/modules/console/controllers/WarmProductGroupsController.php(61): craft\elements\db\ElementQuery-&gt;__call('productStartDat...', Array)
  #5 [internal function]: modules\console\controllers\WarmProductGroupsController-&gt;actionIndex(false)
  #6 /myproject/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
  #7 /myproject/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction-&gt;runWithParams(Array)
  #8 /myproject/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller-&gt;runAction('', Array)
  #9 /myproject/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller-&gt;runAction('', Array)
  #10 /myproject/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module-&gt;runAction('theme/warm-prod...', Array)
  #11 /myproject/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application-&gt;runAction('theme/warm-prod...', Array)
  #12 /myproject/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application-&gt;runAction('theme/warm-prod...', Array)
  #13 /myproject/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application-&gt;handleRequest(Object(craft\console\Request))
  #14 /myproject/craft(22): yii\base\Application-&gt;run()
  #15 {main}
  </code></pre>
  <p>Any hints why?</p>
  
Tags: <plugin-craftcommerce><datetime><custom-field><elementquery>
Title: Commerce element query on custom field in console command
ThreadText: # Commerce element query on custom field in console command
  
  (Asked by: username_0 on 2021-01-28)
  
  I'm on Craft 3.4.30 (latest 3.4) and Commerce 2.2.25 (latest 2.2):
  
  My product type "ticket" has a custom date field with handle `productStartDate`.
  
  E.g. the following query in TWIG works:
  
  ```
  {% set products = craft.products().type('ticket').productStartDate('>= 2021-01-01 00:00:00').all() %}
  
  ```
  
  I get nice results including my custom field `productStartDate`
  
  I am trying the same in a console command with PHP:
  
  ```
  use craft\commerce\elements\Product;
  $product = Product::find()
                  ->type('ticket')
                  ->productStartDate('>= 2021-01-01 00:00:00')
                  ->all();
  
  ```
  
  Gives me this Exception:
  
  ```
  Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: craft\behaviors\CustomFieldBehavior::productStartDate()'
  
  in /myproject/vendor/yiisoft/yii2/base/BaseObject.php:222
  
  Stack trace:
  #0 /myproject/storage/runtime/compiled_classes/CustomFieldBehavior.php(542): yii\base\BaseObject->__call('productStartDat...', Array)
  #1 [internal function]: craft\behaviors\CustomFieldBehavior->__call('productStartDat...', Array)
  #2 /myproject/vendor/yiisoft/yii2/base/Component.php(297): call_user_func_array(Array, Array)
  #3 /myproject/vendor/craftcms/cms/src/elements/db/ElementQuery.php(548): yii\base\Component->__call('productStartDat...', Array)
  #4 /myproject/modules/console/controllers/WarmProductGroupsController.php(61): craft\elements\db\ElementQuery->__call('productStartDat...', Array)
  #5 [internal function]: modules\console\controllers\WarmProductGroupsController->actionIndex(false)
  #6 /myproject/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
  #7 /myproject/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
  #8 /myproject/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('', Array)
  #9 /myproject/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('', Array)
  #10 /myproject/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('theme/warm-prod...', Array)
  #11 /myproject/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('theme/warm-prod...', Array)
  #12 /myproject/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('theme/warm-prod...', Array)
  #13 /myproject/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
  #14 /myproject/craft(22): yii\base\Application->run()
  #15 {main}
  
  ```
  
  Any hints why?
  
  **Tags:** plugin-craftcommerce, datetime, custom-field, elementquery
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-01-29. Score: 1
  
  Found it: the reason for the Exception is, that the dynamic method `productStartDate` (coming from the CustomFieldBehavior) needs an Array as parameter.
  
  I have no clue why I get this misleading Exception though...
  
  So finally, this works:
  
  ```
  use craft\commerce\elements\Product;
  $product = Product::find()
                  ->type('ticket')
                  ->productStartDate(['>="2021-01-01 00:00:00"'])
                  ->all();
  
  ```
  
  
  ---
  
  