2

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));
    }

}
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.