3

This piece of code used to work to retrieve 1 featured (lightswitch) entry per category.

{% for category in craft.categories %}      
    {% set entries = craft.entries.find({
      section:    'news',
      limit:      '1',
      featured : '1',
      search :"category:" ~ category.title,
      order :'postDate desc'
    }) %}

Somehow I have to save a entry twice now before it appears. Any ideas whats wrong? Is this a craft bug?

4

There’s currently a bug with storing keywords based on related elements, which we’re looking into. Using the search parameter for this isn’t really the right way to go anyway, though.

Instead you should be using the relatedTo param:

{% set entries = craft.entries.find({
    section:   'news',
    limit:     1,
    featured:  1,
    relatedTo: { targetElement: category, field: 'category' },
    order:     'postDate desc'
}) %}

UPDATE

The aforementioned bug was fixed in Craft 2.1.2563. You’re still better off using the relatedTo param though.

UPDATE 2

Fixed a typo in the above code block.

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.