C
C
countZer02020-04-13 13:51:33
1C-Bitrix
countZer0, 2020-04-13 13:51:33

How to filter elements by property ID?

Hello !

There is a custom property (binding to elements) that stores the diet ID. The diets themselves are elements in the infoblock, which has properties (multiple binding to elements) for the days of the week. That is, a diet is selected in the user's card, in which, by the days of the week, there is a link to elements in another infoblock (dishes). It is necessary to select all elements (dishes) in accordance with the user's chosen diet. Right now I have this option, but it selects everything, without filtering by diet ID:

$arFilter = Array(
  "IBLOCK_ID" => 19,  
  "ACTIVE"    => "Y",
  "!ID"       => \CIBlockElement::SubQuery("PROPERTY_MON", array(
    "IBLOCK_ID"          => 19,
    "ID"=>$b // $b=тут хранится ID диеты.
  ))
);
  
$productQuery = \CIBlockElement::GetList(
  [],
  $arFilter,
  false,
  false,
  [
    "ID",
    "IBLOCK_ID",
    "NAME",
    "PROPERTY_MON"
  ]
);

while( $arElement = $productQuery->fetch() )
{
  echo "<pre>";
  var_dump($arElement);
  echo "</pre>";
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-04-13
@countZer0

It seems to me that you are too clever with the filter, just try

$arFilter = Array(
  "IBLOCK_ID" => 19,  
  "ACTIVE"    => "Y",
  "PROPERTY_<b>код свойства</b>" => $b
);

UPD above is not correct!!!
You can make 2 queries:
- in the first one, knowing the id of the diet, you get the id-shniks of related elements
- in the second, knowing the related id-shniks, you get these elements

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question