2

I'm trying to show the next post that's not in the array of articles "completed". I have the next articles showing that haven't been completed, however i can't set a limit to just show one article. Any ideas?

here's my code

{% for entry in craft.entries.section(['getStarted', 'rollOut', 'assessAndPrioritize', 'agreeCommit','measureSuccess']).order('stepNumber asc')  %}

    {% set test = currentUser and entry.id not in currentUser.completed.ids()  %}

    {% if test == true %}
        {{entry.title}}<br>
    {% endif %}

{% endfor %}
  • Forgot to mention the limit works on the first article, but when it's "completed" and is in the entries field on the user side, it just shows blank. – Kevin Love Jul 31 '18 at 2:11
2

You need to exclude the ids from the beginning.

{% set excludeIds = currentUser.completed.ids() %}
{% set entry = craft
    .entries
    .section([
        'getStarted',
        'rollOut',
        'assessAndPrioritize',
        'agreeCommit',
        'measureSuccess'
    ])
    .order({stepNumber: SORT_ASC})
    .where(['not in', 'elements.id', excludeIds])
    .one()
%}

.where(['not in', 'elements.id', excludeIds]) will remove all ids in your field from your query.

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.