ExpressionEngine

2.11.9 User Guide

Retired Documentation

You are using the documentation for version 2.11.9. Go here for the latest version or check here for your available upgrades to the latest version.

ExpressionEngine Channel Structure API

Calling the Class

class Api_channel_structure

The Channel Structure class is called with the api->instantiate() function:

ee()->load->library('api'); ee()->api->instantiate('channel_structure');

Function Reference

Get Channel Info

Api_channel_structure::get_channel_info($channel_id)

Fetches all metadata for a channel:

ee()->api_channel_structure->get_channel_info((int) $channel_id);
Parameters:
  • $channel_id (int) – ID of the channel to fetch information for
Returns:

Database result object or FALSE on error

Return type:

CodeIgniter database result object

Get Channels

Api_channel_structure::get_channels([$site_id = FALSE])

Fetches channel names and ids:

ee()->api_channel_structure->get_channels([(int) $site_id]);
Parameters:
  • $site_id (int) – The site ID you want channel information for
Returns:

Database result object or FALSE on error

Return type:

CodeIgniter database result object

Delete Channel

Api_channel_structure::delete_channel($channel_id = ''[, $site_id = NULL])

Delete a channel:

ee()->api_channel_structure->delete_channel((int) $channel_id, [(int) $site_id]);
Parameters:
  • $channel_id (int) – ID of the channel to delete
  • $site_id (int) – Specify the site ID of the channel if necessary
Returns:

Channel Title on successful delete or FALSE on error.

Return type:

String/Boolean

Create Channel

Api_channel_structure::create_channel($data)

Creates a new channel:

ee()->api_channel_structure->create_channel((array) $data);
Parameters:
  • $data (array) – Array of data necessary to create a channel (see below)
Returns:

ID of newly created channel or FALSE on error.

Return type:

Integer/Boolean

At the minimum, channel_title and channel_name must be in the $data array.

Values that may be passed in the data array include:

  • site_id, (int)
  • channel_title, (string)
  • channel_name, (string a-zA-Z0-9_- only)
  • url_title_prefix, (string a-zA-Z0-9_- only)
  • comment_expiration, (int)
  • create_templates, (string yes/no) Also Requires:
    • old_group_id
    • group_name, (string a-zA-Z0-9_- only)
    • template_theme
  • cat_group, (int or array of category group ids)
  • dupe_id
  • status_group
  • field_group
  • channel_url
  • channel_lang
  • group_order

Example Usage:

$data = array(
    'channel_title' => 'News',
    'channel_name'  => 'news',
    'field_group' => 2,
    'channel_url' => 'http://example.com/index.php/news/',
    'status_group'  => 1
);

if (ee()->api_channel_structure->create_channel($data) === FALSE)
{
    show_error('An Error Occurred Creating the Channel');
}

Modify Channel

Api_channel_structure::modify_channel($data)

Update an existing Channel:

ee()->api_channel_structure->modify_channel((array) $data);
Parameters:
Returns:

ID of newly created channel or FALSE on error

Return type:

Integer/Boolean

The channel_id of the channel to be modified is required in the $data array. channel_title and channel_name are also required.

In addition to values in the exp_channels table, values that may be modified include:

  • apply_expiration_to_existing, (bool) only if comment_expiration is set
  • clear_versioning_data, (bool)