Documentation

GetIBlockElementList

CIBlockResult
GetIBlockElementList(
 int iblock_id, 
 int section_id = false, 
 array order = Array("SORT"=>"ASC"), 
 int cnt = 0, 
 array arFilter = Array()
);

The function returns active elements of the information block defined by iblock_id.

Parameters

ParameterDescription
iblock_id The ID of the information block to search for elements.
section_id The ID of the section to search for elements. Set section_id to 0 to obtain elements from the information block root. Optional. By default (false), the function selects all records without any restrictions.
order Optional sort order. Array of the format Array(by1=>order1[, by2=>order2 [, ..]]) where by is the field for sorting. The field can have the following values:
  • sort - sort weight;
  • timestamp_x - modification date;
  • name - name;
  • id - element ID;
  • active_from - date the element is active from;
  • active_to - date until which the element is active.
order is the sort order. Can be asc for ascending sorts or desc for descending.

Default value is Array("sort"=>"asc"). Full list of sorting fields and additional information can be found in CIBlockElement::GetList()
cnt Maximum number of the returned records. Optional. All records are returned by default.
arFilter Optional additional filter by fields in the form of Array("Filtered field"=>"Value", ...). The Filtered field can be one of the following:
  • ID - by the ID;
  • ACTIVE - by the active state (Y|N);
  • NAME - by names (wildcards [%_] allowed);
  • PREVIEW_TEXT - by short text (wildcards [%_] allowed);
  • DETAIL_TEXT - by detailed description (wildcards [%_] allowed);
  • SEARCHABLE_CONTENT - by all searchable content. This includes title, short and detailed descriptions (wildcards [%_] allowed);
  • CODE - by mnemonic identifier (wildcards [%_] allowed);
  • SORT - by sort weight;
  • EXTERNAL_ID - by external ID (wildcards [%_] allowed);
  • TIMESTAMP_X - by modification date;
  • DATE_CREATE - by creation date;
  • DATE_ACTIVE_FROM - by date of beginning of the active state;
  • DATE_ACTIVE_TO - by the date the active state expires;
  • ACTIVE_DATE - do filter by active state dates (DATE_ACTIVE_FROM and DATE_ACTIVE_TO), can be Y or N;
  • IBLOCK_ID - by the information block ID;
  • IBLOCK_CODE - by the information block mnemonic code (wildcards [%_] allowed);
  • IBLOCK_LID - by language (wildcards [%_] allowed);
  • IBLOCK_TYPE - by the block type (wildcards [%_] allowed);
  • IBLOCK_ACTIVE - by the block active state (wildcards [%_] allowed);
  • SECTION_ID - by the parent section;
  • PROPERTY_<property_ID> - by the property value. Wildcards ([%_]) allowed. When searching the "LIST" properties, the search is performed by the ID, not by value ;
  • PROPERTY_<property_ID>_VALUE - by the values for the "LIST" properties. Wildcards ([%_]) allowed. The search is performed by the string value, not by the ID;
  • CATALOG_<CATALOG_FIELD>_<PRICE_TYPE> - by the field CATALOG_FIELD of the price type PRICE_TYPE (price type code). CATALOG_FIELD can be PRICE - price, CURRENCY - currency.
All the filter fields except SECTION_ID and ACTIVE_DATE may have the conditions specified before the name.

The fields SECTION_ID and ACTIVE_DATE may have negation sign ("!") before the name.

The "filter values" are a single value or an array.

The default parameter value is an empty array.
Full list of sorting fields and additional information can be found in CIBlockElement::GetList()

Return Values

The function returns an instance of CIBlockResult with active elements, i.e. those having the flag Active set, valid active period and pertaining to the active parent information blocks of the current site.

Remarks

To facilitate handling the function return values, you can use the method CDBResult::GetNext() returning an array of the information block element fields. All fields returned by this method are HTML compliant and safe. Variables #SITE_DIR#, #IBLOCK_ID#, #EXTERNAL_ID# and #ID# are replaced with their corresponding values (fields LIST_PAGE_URL and DETAIL_PAGE_URL). If the result is empty or the end of collection is reached, false is returned. Other methods of the CDBResult class can also be used, but keep in mind that they do not substitute variables like #SITE_DIR# with their values.

See Also

  • Fields of information block elements
  • GetIBlockElementListEx
  • Example


    <?
    if(CModule::IncludeModule("iblock"))
    {
       // select 10 elements from the section $ID of the information block $BID
       $items = GetIBlockElementList($_GET['BID'], 
                                     $_GET['ID'], Array("SORT"=>"ASC"), 10);
       $items->NavPrint("Products");
       while($arItem = $items->GetNext())
       {
          echo $arItem["NAME"]."<br>";
          echo $arItem["PREVIEW_TEXT"]."<br>";
       }
       $items->NavPrint("Products");
    }
    ?>
    © «Bitrix24», 2001-2024
    Up