Answers.Body: <p>The question is pretty confusing so this answer assumes the following:</p>
  
  <p>You have a Super Table field named <code>entryType</code> with the following cells:</p>
  
  <ul>
  <li><code>featuredIn</code> (checkbox)</li>
  <li><code>showInRandom</code> (checkbox)</li>
  </ul>
  
  <p>And that you are trying to:</p>
  
  <ol>
  <li>Only show rows where <code>showInRandom</code> is checked</li>
  <li>Randomize the order of the rows that are returned</li>
  <li>Limit the returned results to 2</li>
  </ol>
  
  <p>Unfortunately Super Table doesn't support searching based on a block's value, <a href="https://github.com/verbb/super-table/issues/290" rel="nofollow noreferrer">which I see you already know</a>, so you'll have to do it in steps.</p>
  
  <p>First, you need to pull in every Super Table row. Then you need to check if each row has <code>showInRandom</code> checked (side note: a lightswich field would be easier), and add its ID to an array if so. Then you randomize the array and run a Super Table query with those IDs and limit the results to 2.</p>
  
  <pre><code>{# create an array to store the returned IDs #}
  {% set randomRows = [] %}
  
  {# add only the rows with showInRandom selected to the array #}
  {% for row in entry.entryType.all %}
      {% if row.showInRandom.options[0].selected %}
          {% set randomRows = randomRows|merge([row.id]) %}
      {% endif %}
  {% endfor %}
  
  {# randomize the array and run a super table query, limiting to 2 #}
  {% for row in craft.superTable.blocks({
      owner: entry,
      fieldId: 123,
      id: shuffle(randomRows),
      fixedOrder: true,
      limit: 2
  }).all %}
      {{ row.someField }}&lt;br&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-21T23:44:55.280Z
Answers.Text: Sorry that does not work. featuredIn is not a checkbox, it's a field. I did update the question with some screenshots. Seems like i don't get that checkbox thing. Because i also have a field "requiresLogin" and also can't figure out how to make that work.
Answers.UserDisplayName: MrGlasspoole
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-23T19:22:43.317Z
Answers.Text: @MrGlasspoole It would be easier if you updated your question specifically stating *exactly* what you are trying to do.
Answers.UserDisplayName: kmgdev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-18T23:38:32.537Z
Answers.LastActivityDate: 2019-09-18T23:38:32.537Z
Answers.UserDisplayName: kmgdev
Body: <p>I have a Super Table field (entryType) with a checkbox field "featuredIn" and some values.  </p>
  
  <p><a href="https://i.sstatic.net/y8Gh8.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/y8Gh8.jpg" alt="enter image description here"></a></p>
  
  <p>This is how it looks when creating a entry:
  <a href="https://i.sstatic.net/TQnbO.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TQnbO.jpg" alt="enter image description here"></a></p>
  
  <p>I can't figure out how to mix "slice" and "orderBy RAND" with filtering by that field.  </p>
  
  <p>This does show me 2 random entries from all:</p>
  
  <pre><code>{% set entries = craft.entries.section('blog').orderBy('RAND()').all() %}
  
  {% for entry in entries|slice(0, 2) %}
    {{ entry.title }}
  {% endfor %}
  </code></pre>
  
  <p>This shows me only the entries where "showInRandom" is checked (but not random and not only 2):  </p>
  
  <pre><code>{% for entry in craft.entries.section('blog') if entry.entryType.featuredIn.contains('showInRandom') %}
    {{ entry.title }}
  {% endfor %}
  </code></pre>
  
Tags: <craft3><plugin-supertable>
Title: Show 2 random entries based on checkbox in Super Table
ThreadText: # Show 2 random entries based on checkbox in Super Table
  
  (Asked by: username_0 on 2019-09-15)
  
  I have a Super Table field (entryType) with a checkbox field "featuredIn" and some values.
  
  [![enter image description here](https://i.sstatic.net/y8Gh8.jpg)](https://i.sstatic.net/y8Gh8.jpg)
  
  This is how it looks when creating a entry:
  [![enter image description here](https://i.sstatic.net/TQnbO.jpg)](https://i.sstatic.net/TQnbO.jpg)
  
  I can't figure out how to mix "slice" and "orderBy RAND" with filtering by that field.
  
  This does show me 2 random entries from all:
  
  ```
  {% set entries = craft.entries.section('blog').orderBy('RAND()').all() %}
  
  {% for entry in entries|slice(0, 2) %}
    {{ entry.title }}
  {% endfor %}
  
  ```
  
  This shows me only the entries where "showInRandom" is checked (but not random and not only 2):
  
  ```
  {% for entry in craft.entries.section('blog') if entry.entryType.featuredIn.contains('showInRandom') %}
    {{ entry.title }}
  {% endfor %}
  
  ```
  
  **Tags:** craft3, plugin-supertable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-18. Score: 1
  
  The question is pretty confusing so this answer assumes the following:
  
  You have a Super Table field named `entryType` with the following cells:
  
  * `featuredIn` (checkbox)
  * `showInRandom` (checkbox)
  
  And that you are trying to:
  
  1. Only show rows where `showInRandom` is checked
  2. Randomize the order of the rows that are returned
  3. Limit the returned results to 2
  
  Unfortunately Super Table doesn't support searching based on a block's value, [which I see you already know](https://github.com/verbb/super-table/issues/290), so you'll have to do it in steps.
  
  First, you need to pull in every Super Table row. Then you need to check if each row has `showInRandom` checked (side note: a lightswich field would be easier), and add its ID to an array if so. Then you randomize the array and run a Super Table query with those IDs and limit the results to 2.
  
  ```
  {# create an array to store the returned IDs #}
  {% set randomRows = [] %}
  
  {# add only the rows with showInRandom selected to the array #}
  {% for row in entry.entryType.all %}
      {% if row.showInRandom.options[0].selected %}
          {% set randomRows = randomRows|merge([row.id]) %}
      {% endif %}
  {% endfor %}
  
  {# randomize the array and run a super table query, limiting to 2 #}
  {% for row in craft.superTable.blocks({
      owner: entry,
      fieldId: 123,
      id: shuffle(randomRows),
      fixedOrder: true,
      limit: 2
  }).all %}
      {{ row.someField }}<br>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Sorry that does not work. featuredIn is not a checkbox, it's a field. I did update the question with some screenshots. Seems like i don't get that checkbox thing. Because i also have a field "requiresLogin" and also can't figure out how to make that work.  
  > **username_1**: @username_0 It would be easier if you updated your question specifically stating *exactly* what you are trying to do.  
  
  ---
  
  