D
D
Diversia2017-07-13 22:21:25
1C-Bitrix
Diversia, 2017-07-13 22:21:25

Bitrix: how to select elements from several infoblocks with one request?

Can you please tell me if it is possible to select elements from different infoblocks with one request? I tried two options, but it does not work:
1 option

$arSelect = array(
  "ID",
  "NAME",
  "IBLOCK_ID",
  "IBLOCK_CODE",
  "CODE",
  "PROPERTY_photo"
);

$arFilter = array(
  "ID" => $arList, // массив с id всех нужных элементов
  "IBLOCK_ID" => array(3,10),
);

$rsElement = CIBlockElement::GetList(Array("NAME" => "ASC"), $arFilter, false, Array(), $arSelect);
while($arElement = $rsElement->Fetch())
{
  print $arElement["NAME"]. "<br>";
}

Option 2
$arSelect = array(
  "ID",
  "NAME",
  "IBLOCK_ID",
  "IBLOCK_CODE",
  "CODE",
  "PROPERTY_photo"
);

$arFilter = array(
  array(
    "LOGIC" => "OR",
    array("IBLOCK_ID" => 3, "ID" => $genres), // массив с id нужных элементов из 3 ИБ
    array("IBLOCK_ID" => 10, "ID" => $tags), // массив с  id нужных элементов из 10 ИБ
  ),
);

$rsElement = CIBlockElement::GetList(Array("NAME" => "ASC"), $arFilter, false, Array(), $arSelect);
while($arElement = $rsElement->Fetch())
{
  print $arElement["NAME"]. "<br>";
}

In option 1: if you specify only one infoblock, it is displayed. And you need several infoblocks with one request.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2017-07-14
@Diversia

Do not specify IB at all, in general I managed somehow without specifying the IB ID, but it’s better not to do this. Create 2 requests

O
Oleg Mifle, 2017-07-14
@OlegMifle

Try on d7 via ElementTable::getList();.

A
Alexey, 2017-07-17
@rixaman

The first option is working for sure, I did it on my projects, apparently you have a mistake somewhere. How is $arList specified and are those IBLOCK_IDs specified? Without specifying IBLOCK_ID in the filter, it also works, as Sergey said above.
I rechecked it on my project using the example below, it works and displays elements from several infoblocks.

$arSelect = array(
  "ID",
  "NAME",
  "IBLOCK_ID",
  "IBLOCK_CODE",
  "CODE",
  "PROPERTY_PHOTO"
);

$arFilter = array(
  "ID" => array(123,1234,2345),
  "IBLOCK_ID" => array(1,2,3),
);

$rsElement = CIBlockElement::GetList(array("NAME" => "ASC"), $arFilter, false, array(), $arSelect);
while($arElement = $rsElement->Fetch())
{
  echo "<pre>";
  print_r($arElement);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question