Function Reference: wlmapi_add_category_to_level

Gives a membership level access to the specified category.

Parameters

  • level_id (int) – The ID of the level to add categories to
  • args (array) – An array of accepted arguments specified below:
Parameter Description Required Default
ContentIds (array) An array of category IDs to add to the membership level Required

Return

Returns a multi-dimensional array containing operation status and an array containing all the categories successfully added to that membership level.

Example Code

<?php
     $args = array(
          'ContentIds' => array(7,8,9,10)
     );
     $categories = wlmapi_add_category_to_level(1340726008, $args);
     print_r($categories);
?>

Example Output

Array
(
    [success] => 1
    [categories] => Array
        (
            [category] => Array
                (
                    [0] => Array
                        (
                            [ID] => 9
                            [name] => Child Category I
                            [_more_] => /levels/1340726008/categories/9
                        )

                    [1] => Array
                        (
                            [ID] => 10
                            [name] => Child Category II
                            [_more_] => /levels/1340726008/categories/10
                        )

                    [2] => Array
                        (
                            [ID] => 7
                            [name] => Parent Category II
                            [_more_] => /levels/1340726008/categories/7
                        )

                    [3] => Array
                        (
                            [ID] => 8
                            [name] => Parent Category III
                            [_more_] => /levels/1340726008/categories/8
                        )

                )

        )

    [supported_verbs] => Array
        (
            [0] => GET
            [1] => POST
        )

)

Notes

This functions returns WLMAPIMethods::add_category_to_level($level_id, $args) in core/api-helper/class-api-methods.php