I have a query that I need to do that involves using the logged in member ID to limit the results. The following does not work, because the {member_id} variable is not parsed early enough.
{exp:query sql="SELECT ct.title AS title
FROM exp_channel_titles AS ct
WHERE ct.member_id = {member_id};"
}
I've tried to pass {member_id} as an embed as well, but it outputs the actual curly braces again and does not work either:
{embed="members/.favorite-query" member_id="{member_id}"}
{exp:query sql="SELECT ct.title AS title
FROM exp_channel_titles AS ct
WHERE ct.member_id = {embed:member_id};"
}
I then tried to create a global variable using the session_end hook. If I hard code the global variable, the query works, but it turns out that the $this->EE->session array is not available yet when using the session end hook, so I cannot use that method dynamically.
There is a thread on this topic here: http://ellislab.com/forums/viewthread/168569/#804745
I also tried creating a member_id value using a module tag, but again, the parse order is against me.
Am I overlooking any other options available here?