Answers.Body: <p><del>There’s currently a bug with storing keywords based on related elements, which we’re looking into.</del> Using the <code>search</code> parameter for this isn’t really the right way to go anyway, though.</p>
  
  <p>Instead you should be using the <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param" rel="nofollow"><code>relatedTo</code> param</a>:</p>
  
  <pre><code>{% set entries = craft.entries.find({
      section:   'news',
      limit:     1,
      featured:  1,
      relatedTo: { targetElement: category, field: 'category' },
      order:     'postDate desc'
  }) %}
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The aforementioned bug was fixed in <a href="http://buildwithcraft.com/updates#build2563" rel="nofollow">Craft 2.1.2563</a>.  You’re still better off using the <code>relatedTo</code> param though.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Fixed a typo in the above code block.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-03T18:06:03.040Z
Answers.LastActivityDate: 2014-11-11T14:27:15.073Z
Answers.LastEditDate: 2014-11-11T14:27:15.073Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>This piece of code used to work to retrieve 1 featured (lightswitch) entry per category. </p>
  
  <pre><code>{% for category in craft.categories %}      
      {% set entries = craft.entries.find({
        section:    'news',
        limit:      '1',
        featured : '1',
        search :"category:" ~ category.title,
        order :'postDate desc'
      }) %}
  </code></pre>
  
  <p>Somehow I have to save a entry twice now before it appears. Any ideas whats wrong? Is this a craft bug?</p>
  
Tags: <templating><lightswitch>
Title: Retrieving featured entry from a given category
ThreadText: # Retrieving featured entry from a given category
  
  (Asked by: username_0 on 2014-07-03)
  
  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?
  
  **Tags:** templating, lightswitch
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-03. Score: 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](http://buildwithcraft.com/docs/relations#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](http://buildwithcraft.com/updates#build2563). You’re still better off using the `relatedTo` param though.
  
  **UPDATE 2**
  
  Fixed a typo in the above code block.
  
  
  ---
  
  