Answers.Body: <p>Found the answer, simple mistake.</p>
  
  <pre><code>if ($criteria-&gt;code) {
     $query-&gt;andWhere(DbHelper::parseParam('trips.code', $criteria-&gt;code, $query-&gt;params));
  }
  </code></pre>
  
  <p>was needed along with </p>
  
  <pre><code>public function defineCriteriaAttributes() {
  
      return array(
          'templateId'    =&gt; AttributeType::Mixed,
          'code'          =&gt; AttributeType::String,
      );
  }
  </code></pre>
  
  <p>Hopes that helps anyone else who comes across something like this.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-18T03:51:42.377Z
Answers.LastActivityDate: 2015-06-18T03:51:42.377Z
Answers.UserDisplayName: Dale Inverarity
Body: <p>having issues doing the classic element type query, works fine with numerical criteria (id, price etc.) but fails on strings, (code, name etc.). It just returns all elements.</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria('GoWander_Trip');
  $criteria-&gt;code = $code;
  return $criteria-&gt;find();
  </code></pre>
  
  <p>Is there any step im missing in the setup of the element itself (code below)?</p>
  
  <pre><code>public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) {
  
      $query
          -&gt;addSelect('
              trips.code, 
              trips.templateId, 
              trips.start, 
              trips.end, 
              trips.assetId, 
              trips.price, 
              trips.spots, 
              trips.spotsAvailable,
              trips.elements,
              trips.shortDescription
          ')
          -&gt;join('gowander_trips trips', 'trips.id = elements.id');
  
      if ($criteria-&gt;templateId) {
  
          $query-&gt;andWhere(DbHelper::parseParam('trips.templateId', $criteria-&gt;templateId, $query-&gt;params));
      }
  
  }
  </code></pre>
  
Tags: <plugin-development><elementcriteriamodel><elementtype>
Title: Why does a Element Criteria Model Query with Strings on a custom element type not filtering?
ThreadText: # Why does a Element Criteria Model Query with Strings on a custom element type not filtering?
  
  (Asked by: username_0 on 2015-06-18)
  
  having issues doing the classic element type query, works fine with numerical criteria (id, price etc.) but fails on strings, (code, name etc.). It just returns all elements.
  
  ```
  $criteria = craft()->elements->getCriteria('GoWander_Trip');
  $criteria->code = $code;
  return $criteria->find();
  
  ```
  
  Is there any step im missing in the setup of the element itself (code below)?
  
  ```
  public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) {
  
      $query
          ->addSelect('
              trips.code, 
              trips.templateId, 
              trips.start, 
              trips.end, 
              trips.assetId, 
              trips.price, 
              trips.spots, 
              trips.spotsAvailable,
              trips.elements,
              trips.shortDescription
          ')
          ->join('gowander_trips trips', 'trips.id = elements.id');
  
      if ($criteria->templateId) {
  
          $query->andWhere(DbHelper::parseParam('trips.templateId', $criteria->templateId, $query->params));
      }
  
  }
  
  ```
  
  **Tags:** plugin-development, elementcriteriamodel, elementtype
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-06-18. Score: 5 | Accepted answer
  
  Found the answer, simple mistake.
  
  ```
  if ($criteria->code) {
     $query->andWhere(DbHelper::parseParam('trips.code', $criteria->code, $query->params));
  }
  
  ```
  
  was needed along with
  
  ```
  public function defineCriteriaAttributes() {
  
      return array(
          'templateId'    => AttributeType::Mixed,
          'code'          => AttributeType::String,
      );
  }
  
  ```
  
  Hopes that helps anyone else who comes across something like this.
  
  
  ---
  
  