2

I'm trying to display a list of favorited entries. I have a wishlist with entry id's build with Shortlist. So now I want to display them but it doesn't work. The first part getting the favorited id's works perfect.

Here is my code so far:

        {% set favIds = [] %}

        {# LOOP TRUE FAV IDS AND MAKE ARRAY #}
        {% for list in lists %}
            {% if list.items is empty %}
            <p>No wishlist</p>
            {% else %}
                {% for entry in list.items %}
                    {% set favId = entry.id %}
                    {% set favIds = favIds|merge([favId]) %}
                {% endfor %}
            {% endif %}
        {% endfor %}

        {# CONVERT favIds array in comma separated list #}
        {% set favIdString = favIds|join(', ') %}

        {% set wishlist = craft.entries.id(favIdString).fixedOrder('true') %}       

        {% for entry in wishlist %}
            {{ entry.title }}
        {% endfor %}

But nothing shows up. If I output {{ favIdString }} I get a nice list if entry ID's. 9619, 9620, 9621, 9622, 9624, 9625

4
  • I just did a test locally and it worked fine for me. Are you sure that 9619, 9620, 9621, 9622, 9624, 9625 are all valid entry IDs? You can check by looking id column in the craft_entries table. – Brad Bell Mar 26 '15 at 16:04
  • Also, use fixedOrder(true) instead of fixedOrder('true'). Yours is working because of PHP loose type-casting, but it's better to be explicit, IMO. – Brad Bell Mar 26 '15 at 16:06
  • Ah there it is... ID's are wrong. Haha. Ok will try to fix it and get the right ID's. – Johannes Lamers Mar 26 '15 at 16:07
  • Cool... would you mind adding that as the official answer, please? – Brad Bell Mar 26 '15 at 16:08
4

Turns out... the ID's are wrong. I've listed the shortlist ID's and not the entry ID's. Should use entry.elementId.

Here's the fix:

 {% for entry in list.items %}
      {% set favId = entry.elementId %}
      {% set favIds = favIds|merge([favId]) %}
 {% endfor %}
1
  • Hi, Thanks, it works! But how do I use the {{ item.removeActionUrl }}? – Martijn La Feber Sep 16 '16 at 22:22

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.