0

I'm trying to write a custom SQL query like this:

{exp:query sql="
    SELECT channel_short_name
    FROM what_table_is_it_in
    WHERE entry_id = '{embed:entry_id}'"
}
{channel_short_name}
{/exp:query}

It's inside an embed template with an entry_id passed in as {embed:entry_id}. I just need it to output the channel short name for that channel of that entry.

What database table is this in? I can't find it!

I'm trying to replicate the example at the very bottom of this page: http://www.solspace.com/docs/rating/entries/ except I want to get channel_short_name instead of entry title.

1 Answer 1

1

Channel titles are stored in the (exp_)channels table in the channel_name column, so you'll have to do a join to get the information you need.

{exp:query sql="SELECT c.channel_name as channel_shortname FROM exp_channels as c LEFT JOIN exp_channel_titles as ct on c.channel_id = ct.channel_id WHERE ct.entry_id = '14'"}
    {channel_shortname}
{/exp:query}

In this case, I would use a regular channel entries loop instead of a query loop. I don't think it would produce much more queries if you disable everything.

{exp:channel:entries disable="categories|category_fields|custom_fields|member_data|pagination" entry_id="{embed:entry_id}" limit="1" dynamic="no"}
    {channel_short_name}
{/exp:channel:entries}
3
  • Thanks. Don't know why I didn't think of that ;-) Jul 24, 2013 at 7:58
  • Added the query you would need. Try running both and choose the least expensive solution. Jul 24, 2013 at 8:09
  • When I use stash, I generally use stash embeds with process="start" (essentially the same as a snippet). Since that is processed first, I can use all the variables from the father template directly. Jul 24, 2013 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.