1
{exp:tag:related_entries
    entry_id="{embed:entry_id}"
    orderby="relevance" sort="desc"
    limit="10"
    {if '{embed:channel}' != ''}channel="{embed:channel}"{/if}
}

<?php if (!in_array('{entry_id}', $filtered_ids)) { ?>

    {exp:stash:append_list name="my_list" parse_tags="yes"}
        {stash:id}{entry_id}{/stash:id}
        {stash:item_title}{title}{/stash:item_title}
        {stash:item_category}{categories}{category_name}{/categories}{/stash:item_category}
        {stash:item_category_url}{categories}{category_url_title}{/categories}{/stash:item_category_url}
        {stash:item_channel_name}{channel_name}{/stash:item_channel_name}
        {stash:item_channel_name}{channel_name}{/stash:item_channel_name}
        {stash:item_hero}{hero}{/stash:item_hero}
    {/exp:stash:append_list}

<?php } ?>

{/exp:tag:related_entries}

Why is the above not filtering entries, when the code below works as expected:

{exp:tag:related_entries
    entry_id="{embed:entry_id}"
    orderby="relevance" sort="desc"
    limit="10"
    {if '{embed:channel}' != ''}channel="{embed:channel}"{/if}
}

    <?php if (!in_array('{entry_id}', $filtered_ids)) { ?>

    do display - {entry_id} 

    <?php } else { ?>
    do not display - {entry_id} 
    <?php } ?>

{/exp:tag:related_entries}

I'm trying to filter entries, I have a list of entries that I dont want to display, which I've converted to an array, but when I add the stash append_list code it contains all the entires, even those that will get printed as 'entry_id do - not display' when I run the first code.

1

If anyone else is interested, I solved this by hacking the Tag module (which is very nicely written) and added an 'exclude_ids' parameter to the 'related_entries' tag, which when set, filters out the provided ids from the results.

    if (ee()->TMPL->fetch_param('exclude_ids'))
    {
        $exclude_ids = ee()->TMPL->fetch_param('exclude_ids');

        $filtered_list = rtrim($exclude_ids, '|');
        $filtered_ids = str_replace("|", ",", $filtered_list);

        $sql .= " AND te1.entry_id NOT IN ($filtered_ids) "; 
    }

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.