<p>I believe I have found the answer.</p>

<pre><code>if(array_key_exists('byCategory', $filterAttributes))
{
  foreach ($entry-&gt;getFieldLayout()-&gt;getFields() as $key) 
  {
      $field = $key-&gt;getField();
      if($field-&gt;type == "Categories"){

         if(!$this-&gt;addFilterdCategories($entry[$field-&gt;handle],$filterAttributes))
         {
             continue;
         }
      }
   }
}
</code></pre>

CC BY-SA 3.0
2015-01-19T23:57:53.290Z
2015-01-19T23:57:53.290Z
a-am
<p>In my plugin I need to loop through an entry's fields and if that field is a field type of "Categories" use that entry field value/s. </p>

<p>This is what I have tried so far.</p>

<pre><code>if(array_key_exists('byCategory', $filterAttributes))
{
  foreach ($entry-&gt;getFieldLayout()-&gt;getFields() as $key) 
  {
      $field = $key-&gt;getField();
      if($field-&gt;type == "Categories"){

         if(!$this-&gt;addFilterdCategories($field,$filterAttributes))
         {
             continue;
         }
      }
   }
}
</code></pre>

CC BY-SA 3.0
2015-01-19T22:43:03.433Z
What code do you have so far? It may help us to know what your starting point is.
Lindsey D
CC BY-SA 3.0
2015-01-19T22:59:41.060Z
@LindseyD I added code I have tried into the original post.
a-am
<plugin-development>
Loop through an entry's fields and if the field type is "Categories" get that fields value/s
# Loop through an entry's fields and if the field type is "Categories" get that fields value/s

(Asked by: username_0 on 2015-01-19)

In my plugin I need to loop through an entry's fields and if that field is a field type of "Categories" use that entry field value/s. 
This is what I have tried so far.
if(array_key_exists('byCategory', $filterAttributes))
{
  foreach ($entry->getFieldLayout()->getFields() as $key) 
  {
      $field = $key->getField();
      if($field->type == "Categories"){

         if(!$this->addFilterdCategories($field,$filterAttributes))
         {
             continue;
         }
      }
   }
}

**Tags:** plugin-development

> **Comments:**
> **username_1**: What code do you have so far? It may help us to know what your starting point is.  
> **username_0**: @LindseyD I added code I have tried into the original post.  

---

## 1 answers

### Answer by username_0 on 2015-01-19. Score: 2 | Accepted answer

I believe I have found the answer.
if(array_key_exists('byCategory', $filterAttributes))
{
  foreach ($entry->getFieldLayout()->getFields() as $key) 
  {
      $field = $key->getField();
      if($field->type == "Categories"){

         if(!$this->addFilterdCategories($entry[$field->handle],$filterAttributes))
         {
             continue;
         }
      }
   }
}


---

