1

I'm hoping someone can give me a pointer on narrowing my returned entries on the basis of nested playa parent relationships. Here's the scoop:

I have a 4 inter-related channels: companies, people, tasks and task statuses. Companies are at the top of the food chain - a lot of the display of the entries in my channels is determine by the company.

People are assigned to companies. When the user logs in, their parent company is stashed as a site variable (member_company_id).

Tasks are assigned to companies, and tasks may be shared with multiple companies since they are one central list of tasks. Tasks therefore have a playa relationship field assigned to the companies channel. On the home screen, when the user logs in, they need to see the list of tasks assigned to their company.

So far, all of the above works nicely with playa parents. Where I'm having trouble is the next layer.

My task statuses channel includes 2 playa fields - one for related company and one for related task. The idea being that each company will be assigning a "status" to each task they have been assigned. But because the task itself is not exclusive to the company, the task status must be an entry whose display is based on both relationship fields at the same time. I thought that the relationship to companies would cascade down through the nested parent chain, but I'm discovering that they are not. Here's my template code:

{exp:stash:get_list name="member_details" limit="1"}
{exp:channel:entries channel="comp" limit="1" entry_id="{member_company_id}" orderby="date" sort="desc" disable="member_data|pagination" dynamic="no" cache="yes" refresh="720"}

{!-- FETCH TASKS ASSIGNED TO CURRENT LOGGED IN MEMBER COMPANY --}

{exp:playa:parents channel="tasks" field="cf_tasks_related_companies" var_prefix="tasks"}

    <div class="row">
        <div class="large-8 columns">
            <h5>{tasks:title}</h5>
            <p class="smaller">{tasks:cf_tasks_description}</p>
        </div>

        <div class="large-4 columns">
            {!-- FETCH STATUS OF EACH TASK --}

            {tasks:exp:playa:parents limit="1" channel="status" field="cf_status_related_task" var_prefix="status"}
                {if status:no_parents}<a href="#" class="button tiny secondary" data-reveal-id="updateStatusModal">Add Status</a>{/if}
                <div class="smaller" style="margin-bottom: 1.0em;">
                    <div>Status: {status:cf_status_current:label}</div>
                    <div>Target: {status:cf_status_target_date format="%M %d %Y"}</div>
                </div>
                <p><a href="#" class="button tiny secondary" data-reveal-id="updateStatusModal">Update Status</a></p>
            {/tasks:exp:playa:parents}
        </div>

    </div>

{/exp:playa:parents}

{/exp:channel:entries}
{/exp:stash:get_list}

What I'm finding is that when I log in as a member of company XYZ, I correctly get the tasks assigned to that company. However, the task statuses being returned by tasks:exp:playa:parents are not limited to the company and instead I'm getting all task statuses assigned to task A.

Is there a way to limit the returned entries in the fashion I am looking for with the nested parents tags, or am I going to need a custom query?

2
  • To clarify: you need to answer the question "in what Task Status entry is this Company selected in the cf_status_related_company field and this Task selected in the cf_status_related_taskfield"? Jan 7, 2014 at 14:42
  • Yes. The company is the top-level parent. In the tasks channel, there is a related companies field (multiple selections available). Within the task status channel, there is a custom field for related company AND a field for related task. I have a parent loop pulling the tasks for the logged in member's company easily. But when presenting the task statuses I need to limit to its parent related task, and also its parent company. I have so far managed to rig it up with a coparents loop embed, passing the task and company as params, but it's ugly. Jan 7, 2014 at 18:10

1 Answer 1

1

Have you tried adding to your task status lookup a search parameter that further filters what Playa returns? Based on your description, I think you'd want to add:

search:cf_status_related_company="={member_company_id}"

So, what you have here:

{tasks:exp:playa:parents limit="1" channel="status" field="cf_status_related_task" var_prefix="status"}

Would be changed to:

{tasks:exp:playa:parents limit="1" channel="status" field="cf_status_related_task" search:cf_status_related_company="={member_company_id}" var_prefix="status"}

If Playa search works the way I think, this would filter out your task statuses to just those that matched the {member_company_id}.

Does that work?

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.