Bitrix Site Manager

CIBlock::GetList

CDBResult
CIBlock::GetList(
 array arOrder = Array("SORT"=>"ASC"),
 array arFilter = Array(),
 bool bIncCnt = false
);

Returns a list of information blocks filtered by arFilter and sorted by arOrder.

Parameters

ParameterDescription
arOrder 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:
  • id - section ID;
  • iblock_type - section type;
  • name - name;
  • active - active state;
  • sort - sort weight;
  • active - active sign;
  • element_cnt - number of elements (if bIncCnt is true);
  • timestamp_x - modification date;
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()
arFilter Optional additional filter by fields in the form of Array("Filter field"=>"filter values", ...). The Filtering field can be one of the following:
  • ACTIVE - by the active state (Y|N);
  • NAME - by names (wildcards [%_] allowed);
  • EXTERNAL_ID, XML_ID - by external ID;
  • SITE_ID - by site;
  • TYPE - by the section type;
  • CODE - by mnemonic identifier;
  • ID - by the ID;
  • CNT_ACTIVE (if only bIncCnt is true). If set to "Y", only the active elements are counted and the result is set as the value of the field ELEMENT_CNT. Otherwise, all elements are counted;
  • CNT_ALL (if only bIncCnt is true). If set to "Y", the unpublished elements are also counted and the result is set as the value of the field ELEMENT_CNT. Otherwise, all other elements are only counted.
All the filtering fields may have the conditions specified before the name.

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

The default parameter value is an empty array.

bIncCnt Specifies that the number of elements of the information block is to be returned in the field ELEMENT_CNT. Optional. The default value is false.

Return Values

Returns an instance of CDBResult.

See Also

  • CDBResult
  • CIBlock fields

    Example


    <?
    // select all active information blocks of the type catalog of the current site
    // selection is limited to all blocks with mnemonic code other than my_products,
    // return the number of active elements.
    $res = CIBlock::GetList(
        Array(), 
        Array(
            'TYPE'=>'catalog', 
            'SITE_ID'=>SITE_ID, 
            'ACTIVE'=>'Y', 
            "CNT_ACTIVE"=>"Y", 
            "!CODE"=>'my_products'
        ), true
    );
    while($ar_res = $res->Fetch())
    {
        echo $ar_res['NAME'].': '.$ar_res['ELEMENT_CNT'];
    }
    ?>