Answers.Body: <p>Assuming your Super Table field has a handle of <code>colors</code>, you should be able to do:</p>
  
  <pre><code>foreach ($entry-&gt;colors as $block) {
      // Color will return a category element query, so you can do:
  
      // Return a collection of all category ids
      Craft::dump($block-&gt;color-&gt;ids());
  
      // Get the first category
      Craft::dump($block-&gt;color-&gt;one());
  
      // Get all the categories in the field
      Craft::dump($block-&gt;color-&gt;all());
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-10T14:06:05.013Z
Answers.LastActivityDate: 2019-09-10T14:06:05.013Z
Answers.UserDisplayName: crawf
Body: <p>I have a Super Table field with two columns, one is a category field, the other an assets field (limit 1 on both). How can I iterate through it to get the category and asset selected for each row in the table?</p>
  
  <pre><code>$superTable = $entry-&gt;colors;
  foreach ($superTable as $row) {
      // Category field handle is `color`
      // Asset field handle is `image`
  
      // I've tried various things here, but I don't understand how to get the fields
      // I'm looking for the category ID and asset ID in every row of the table
  }
  </code></pre>
  
Tags: <plugin-development><plugin-supertable>
Title: Iterate through Super Table field in plugin
ThreadText: # Iterate through Super Table field in plugin
  
  (Asked by: username_0 on 2019-02-09)
  
  I have a Super Table field with two columns, one is a category field, the other an assets field (limit 1 on both). How can I iterate through it to get the category and asset selected for each row in the table?
  
  ```
  $superTable = $entry->colors;
  foreach ($superTable as $row) {
      // Category field handle is `color`
      // Asset field handle is `image`
  
      // I've tried various things here, but I don't understand how to get the fields
      // I'm looking for the category ID and asset ID in every row of the table
  }
  
  ```
  
  **Tags:** plugin-development, plugin-supertable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-10. Score: 1 | Accepted answer
  
  Assuming your Super Table field has a handle of `colors`, you should be able to do:
  
  ```
  foreach ($entry->colors as $block) {
      // Color will return a category element query, so you can do:
  
      // Return a collection of all category ids
      Craft::dump($block->color->ids());
  
      // Get the first category
      Craft::dump($block->color->one());
  
      // Get all the categories in the field
      Craft::dump($block->color->all());
  }
  
  ```
  
  
  ---
  
  