Skip to content

Instantly share code, notes, and snippets.

@mmcachran
Created June 27, 2012 16:05
Show Gist options
  • Save mmcachran/5a9a459aea335494fb71 to your computer and use it in GitHub Desktop.
Save mmcachran/5a9a459aea335494fb71 to your computer and use it in GitHub Desktop.
Expression Engine 2 Queries
# Fetch Channel Fields
SELECT
fg.group_id,
fg.group_name,
cf.field_id,
cf.field_label,
cf.field_order,
cf.field_name,
cf.field_type
FROM
exp_field_groups fg
LEFT JOIN
exp_channel_fields cf
ON fg.group_id = cf.group_id
ORDER BY fg.group_name, cf.field_order ASC
# Example Usage
<?php
public function fetch_channel_fields()
{
$data = array();
$query = "
SELECT
fg.group_id,
fg.group_name,
cf.field_id,
cf.field_label,
cf.field_order,
cf.field_name,
cf.field_type
FROM
exp_field_groups fg
LEFT JOIN
exp_channel_fields cf
ON fg.group_id = cf.group_id
ORDER BY fg.group_name, cf.field_order ASC
";
$fields = $this->EE->db->query($query);
if( $fields->num_rows() > 0 )
{
foreach( $fields->result_array() as $row )
{
$data[ $row['group_id'] ][ $row['field_id'] ] = $row;
}
}
return print_r($data);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment