php – Get elements by property description string


There is a multiple property of the string type: "CML2_TRAITS" , you need to get elements whose description field (DESCRIPTION) contains the string "Зачеркнутая цена" . This is how it returns elements whose value contains "2 900" , but you need to DECRIPTION field.

$arSelect = Array();
$arFilter = Array("IBLOCK_ID"=>8, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y", "PROPERTY_CML2_TRAITS" => "%2 900%");
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>50), $arSelect);
while($ob = $res->GetNextElement())
 $arFields = $ob->GetFields();

This is how it works as it should, the $oldPriceFilter contains the IDs of the required elements, but there is a problem with performance, first all the catalog elements are enumerated, and then from them by properties. Is there an easier solution?

$arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM","PROPERTY_*");
$arFilter = Array("IBLOCK_ID"=>8, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y");
$oldPriceFilter = array();
$res = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
while($ob = $res->GetNextElement())
 $arFields = $ob->GetFields();
 $arProps = $ob->GetProperties();
 //echo "<pre>";
// print_r($arFields['ID']);
// echo "</pre>"; 
 $oldPriceArray = $arProps['CML2_TRAITS']['DESCRIPTION'];
 if (in_array("Зачеркнутая цена", $oldPriceArray))  $oldPriceFilter[] = $arFields['ID'];

 echo "<pre>";
 echo "</pre>";


Technical support answer: "You cannot filter by the DESCRIPTION field."

Scroll to Top