I'm trying to fetch a channel entry's data from within a plugin. I was surprised that ExpressionEngine's Channel Entries API includes functions for creating, updating, deleting, and checking whether an entry exists, but no function to get a channel entry. So I'm trying to use Codeigniter's
db->get() function to fetch this data.
First, I tried just fetching the channel data:
$query = $EE->db ->select('*') ->from('exp_channel_titles') ->join('exp_channel_data', 'exp_channel_data.entry_id = exp_channel_titles.entry_id') ->where('exp_channel_titles.entry_id' => 1) ->get(); $result = $query->result_array(); var_dump($result);
This returns all of the channel entry's data except relationship data, unfortunately. My custom channel field with an ID of 106 is a relationship field, and I can set and update it through the ExpressionEngine CMS just fine, but when fetching the
channel_data in this way the field is blank and its field type is (strangely) set to "xhtml":
["field_id_106"]=> string(0) "" ["field_ft_106"]=> string(5) "xhtml"
Next I considered that maybe I need to join the
exp_relationships table to this query by adding a second join:
->join('exp_relationships', 'exp_relationships.parent_id = exp_channel_titles.entry_id', 'left outer')
But this still returns a blank string of fieldtype "xhtml" for my relationship
field_id_106 in the channel data returned. So, any thoughts on how to fetch relationship data along with the rest of the channel data using Codeigniter in ExpressionEngine?