We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

submit_new_entry and Relationship Custom Fields

Development and Programming

OwanH's avatar
OwanH
87 posts
14 years ago
OwanH's avatar OwanH

Hi, I am working on an add-on for a site running EE 2.3.1. I have two channels set up, call them channel A and channel B. Channel A has relationship custom fields to link multiple entries from channel B to a single channel A entry. Now, channel B has been populated manually with all it’s entries. I am now attempting to use the EE channel entry API’s submit_new_entry method to programmatically create new entries in channel A using data I am importing from an XML file. The XML file indicates which of channel B’s entries are to be “related to” for each new channel A entry that will be created.

The EE documentation gives you very basic info. on programmatically creating new channel entries via the API. So by following what I have found in the docs, this is what I have. To add new entries to channel A (has an ID of 77) I do:

$data = array(
 'title' => (string)$attributes['name'],
 'entry_date' => "{$entry_date}",
 'channel_id' => "77",
 'status' => 'open',
 'field_id_22' => serialize($price),
 'field_ft_22' => 'none',
 'field_id_84' => "Yes",
 'field_ft_84' => 'none'
 'field_id_78' => ... what do I put here to specify relationship data to initialize the entry with??
);
             
$this->EE->api_channel_fields->setup_entry_settings("77", $data);
if ($this->EE->api_channel_entries->submit_new_entry("77", $data) === FALSE)
{
 ...

In the above code snippet, ‘field_id_78’ is the field ID of one of the relationship custom fields for pointing to a channel B entry. Keep in mind that ALL of channel B’s entries have already been manually added so I could easily query the DB to get the IDs of any of channel B’s entries. The XML file that is being imported contains a list of the entries to add to channel A and for each of these entries it provides a list of all entries in channel B that the channel A entry has a relation to. So for instance here is a sample piece of the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<channelAItems>
 <channelAItem name="12oz Hot Coffee">
  ...</price>
  <channelBItems>
   <channelBItem name="Beverages">
   <channelBItem name="Breakfast">
  </channelBItems>
 </channelAItem>

 <channelAItem name="Cherry Cheese Cake">
  ...</price>
  <channelBItems>
   <channelBItem name="Desserts">
   </channelBItems>
 </channelAItem>
 ...

The channelBItem name attribute values map exactly to the titles of entries in channel B. Can anyone help me with this? Hope I have been clear.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.