Answer the question
In order to leave comments, you need to log in
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>";
}
$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>";
}
Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question