0

Within a loop, I need to output different info according to whether an entry is in an array of id's or not.

I currently get the id's from a query on the matrix table.

So I need something like this:

{exp:channel:entries channel="article"}

{if entry_id not in (ids)}
    //some output
{if: else}
    //some other output
{/if}

{/exp:channel:entries}

I can't use stash, and I can't figure how to do this with PHP/embedded templates/query tag, I think the parse order is a problem.

Here is the query I use to get the entries to filter on:

SELECT entry_id FROM exp_channel_titles
WHERE entry_id in 
(SELECT `child_entry_id` FROM (`exp_playa_relationships`)
WHERE `parent_field_id` =  '{embed:parent_field_id}'
ORDER BY `rel_order`)
5
  • Are we taking just a few key entry_ids? Or a few hundred out of a thousand? And what makes them special? There is almost certainly another identifier other than being in some random set of entry_ids.
    – jrothafer
    Oct 1, 2015 at 12:01
  • Are you using group_concat()?
    – Sobral
    Oct 1, 2015 at 12:16
  • @jrothafer - there will be up to 200 entries in total, the filter will be 20 entries
    – wot
    Oct 1, 2015 at 12:22
  • 1
    After I improved my answer, I saw your update. You're using Playa, not Matrix. You're doing something really complex. Why not to use {exp:playa:child_ids} on parent template?
    – Sobral
    Oct 1, 2015 at 13:32
  • sorry, it's playa in a matrix field!
    – wot
    Oct 1, 2015 at 13:41

2 Answers 2

1

Are you using version 2.9+? Which is the separator?

Let's pretend you're and the separator is ,, giving you something like 1,2,3,4,5. Let's use the contains and the concatenation operators.

Using Query Module

{exp:query sql="SELECT GROUP_CONCAT(entry_id SEPARATOR ',') AS array_of_ids FROM exp_matrix_data WHERE [...]" parse="inward"}

    {exp:channel:entries channel="article"}

    {if ",".array_of_ids."," *= ",".entry_id.","}
        //some output
    {if: else}
        //some other output
    {/if}

    {/exp:channel:entries}

{/exp:query}

Using {exp:playa:child_ids}

{exp:channel:entries channel="article"}

{if ","."{exp:playa:child_ids entry_id='{embed:parent_field_id}' field_id='XXXX' delimiter=','}"."," *= ",".entry_id.","}
    //some output
{if: else}
    //some other output
{/if}

{/exp:channel:entries}
4
  • Thank you, this is almost there, how do I get the array of ids, I don't think an embed will work?
    – wot
    Oct 1, 2015 at 12:43
  • @wot Like my first comment, what is the criteria that creates this group of entry_ids to be filtered? I guarantee there is a better way, like using categories to tag entries you want to skip.
    – jrothafer
    Oct 1, 2015 at 12:47
  • The group of ids is fetched from a matrix field in another channel
    – wot
    Oct 1, 2015 at 12:52
  • You can write a custom query. But @jrothafer is right. Maybe there is a simpler way.
    – Sobral
    Oct 1, 2015 at 12:54
1

If your goal is separate these specific entries and output them differently, use categories. You can then have content editors easily select (from the entry_form) entries that should be treated as such. You could have just a single category for this channel. Say it had category_id 10:

{exp:channel:entries channel="article"}

    {categories}

        {if category_id == "10"}
            // Special output, in our special group
        {if:else}
            // Regular output, not so special
        {/if}

    {/categories}

{/exp:channel:entries}

Edit

Ok, you get this info from a matrix field. How do you fetch it? Is it via a {exp:query} tag, or do you get it from another {exp:channel:entries} loop? I possibly smell a terrible PHP answer coming your way. Please continue to expand on your question with details.

3
  • I can't add categories to the entries, they are from a matrix field in another channel, so I'd still have to fetch the entries and loop through them.
    – wot
    Oct 1, 2015 at 12:58
  • I don't yet have a way to get the entries, this is part 2 of my problem, I have the sql but how do I use the results?
    – wot
    Oct 1, 2015 at 13:00
  • Please, @wot! Add the query you're using to your question, so I can help you. We can't write a query without to know why.
    – Sobral
    Oct 1, 2015 at 13:03

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.