I
I
Irek Sitdikov2016-07-05 10:13:54
1C-Bitrix
Irek Sitdikov, 2016-07-05 10:13:54

How to search for infoblock elements in Bitrix using the “or” rule?

How to form the $arFilter array in the method:

CIBlockElement::GetList($arSort, $arFilter, false, $arNavParams, $arSelect);

so that you can search by the search word, which can be present in the field "NAME" and "DETAIL_TEXT"?
The following construction works according to the "AND" rule, but it is necessary according to the "OR" rule:
$arFilter = array(
  'NAME' => '%' . $text . '%',
  'DETAIL_TEXT' => '%' . $text . '%'
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2016-07-05
@sitdirek

The arFilter parameter can contain nested filters. The nested filter array key must be a number. For example:
$arFilter = array("NAME" => "A%", array(..<здесь пары "поле" => "фильтр">...), "IBLOCK_ID" => $IBLOCK_ID);

The nesting of filters is theoretically unlimited.
Also, filter conditions can be combined not only by the "AND" condition, but also by "OR". To do this, specify "LOGIC" as the filtered field. It can take two values: "AND" and "OR". The default is "AND". For example, let's choose small ripe and large unripe oranges:
$arFilter = array(
    "IBLOCK_ID" => $IBLOCK_ID,
    "SECTION_CODE" => "orange",
    "INCLUDE_SUBSECTIONS" => "Y",
    array(
        "LOGIC" => "OR",
        array("<PROPERTY_RADIUS" => 50, "=PROPERTY_CONDITION" => "Y"),
        array(">=PROPERTY_RADIUS" => 50, "!=PROPERTY_CONDITION" => "Y"),
    ),
);

CIBlockElement::GetList()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question