1

I have a fairly complicated sequence of queries that I need run in order as later queries rely on results from a previous query and I'm using PHP to help refine and save data. I need to pass in a PHP value into two of my EE queries but I can't get a result and I'm presuming it's a parse order issue. Can anyone advise me on how to fix this? I need to make the "category" parameter in the 2nd EE query dynamic, its currently hardcoded as 51.

    {!-- get category for approved skill --}
{exp:channel:entries 
    channel="skills" 
    status="open"
    entry_id="{segment_2}" 
    limit="1"
    dynamic="no"
    disable="member_data|pagination"
}
    {categories}
        <?php $cats[] = "{category_id}"; ?>
    {/categories}

    <?php $cat = end($cats);?>

{/exp:channel:entries}



{!-- get total number of skills belonging to category --}
{exp:channel:entries 
    channel="skills" 
    status="open"
    category="51"
    dynamic="no"
    disable="member_data|pagination"
}

    <?php $skill_count = "{total_results}";?>

{/exp:channel:entries}
1

Well... You can't do that in a easy way, because the first exp:channel:entries need a PHP parsing on output, but the second one need it on input.

You can, of course use an embed.

[...]
    {embed="all/categories" ids="{categories}{category_id}|{/categories}"}
[...]

But is simpler to use the related_categories_mode on the second exp:channel:entries.

{!-- get total number of skills belonging to category --}
{exp:channel:entries 
    channel="skills" 
    status="open"
    related_categories_mode="yes"
    limit="100"
}
    {total_results}    
{/exp:channel:entries}
| improve this answer | |
  • Hi, thanks for your response. I tried using an embed but I need to save the value of total_results as a PHP variable and this doesn't get returned to the parent template from the embed template. The related categories mode is perfect apart from the "skill" is 3 categories deep and it's bringing back all the skills listed in the parent category whereas I need just the child category. Do you know how i could limit the depth? – KoalaKid Nov 19 '14 at 20:38
  • Ok, I worked that part out using category="not 37|59". Really appreciate the help, worked like a charm. – KoalaKid Nov 19 '14 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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