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

Using related_entries outside of {exp:channel:entires}

Development and Programming

Ralph's avatar
Ralph
78 posts
14 years ago
Ralph's avatar Ralph

Hi.

I have a question about how relations work in EE. I have replaced a {exp:channel:entires} tag with my own custom plugin that takes the results from the db, however I’ve found that the {related_entries} tag doesn’t work outside the {exp:channel:entries} tag. Here is the original code:

{exp:channel:entries channel="professional_calendar" limit="10" orderby="start_date" sort="asc" dynamic_parameters="category|entry_date"}
<input type="hidden" name="business" value="{related_entries id="practitioner"}{paypal_details}{/related_entries}">
....

Here is my new code (which doesn’t work). I tried making a {exp:channel:entries} tag which selects by practitioner (the relation field that contains the dropdown to the paypal channel) but it appears the relation field doesn’t refer to the entry_id. What does the value in relation fields refer to and what’s the best way to get this working again?

{exp:myplugin:get_data channel_id="22" page_size="5"}
{exp:channel:entries channel="paypal" entry_id="{practitioner}"}
<input type="hidden" name="business" value="{paypal_details}"/>
{/exp:channel:entries}
...

Thanks!

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

What is stored in the relationship field is the rel_id from the exp_relationships table. You will probably want the rel_child_id from the exp_relationships table to pass into the entries tag.

       
Ralph's avatar
Ralph
78 posts
14 years ago
Ralph's avatar Ralph

Thanks! I’ve added that to the mysql statement in my plugin. It’s a shame there isn’t an easier way to do this kind of thing without having to go into the database.

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

This might be of interest too: http://ellislab.com/forums/viewthread/196050/

       
Ralph's avatar
Ralph
78 posts
14 years ago
Ralph's avatar Ralph

Thanks for that I’ll consider it in the future. In case it’s useful to anyone here’s my beast of an sql statement. Fields with $ before them are php variables.

SELECT t.title,  exp_channel_data.*,
    pract.$paypal_details_field as paypal_details
FROM exp_channel_titles as t
LEFT JOIN exp_channel_data ON exp_channel_data.entry_id=t.entry_id 
LEFT JOIN  exp_category_posts ON exp_category_posts.entry_id=t.entry_id
LEFT JOIN exp_relationships ON exp_relationships.rel_id=exp_channel_data.$practitioner_field
LEFT JOIN exp_channel_data pract ON pract.entry_id=exp_relationships.rel_child_id
WHERE t.channel_id=$channel_id
AND (exp_category_posts.cat_id=$cat_id or $cat_id IS NULL)
AND ($month_min IS NULL OR exp_channel_data.$start_date_field_name>=$month_min)
AND ($month_max IS NULL OR exp_channel_data.$start_date_field_name<=$month_max)
AND t.status='open'
AND t.entry_date<unix_timestamp(CURDATE())
AND (t.expiration_date>unix_timestamp(CURDATE()) OR t.expiration_date=0)
ORDER BY exp_channel_data.$start_date_field_name
       

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.