<p>Given an array of field IDs, I want to get all content for those fields.
So, in this situation:</p>

<ul>
<li>entry 1
<ul>
<li>field ID 1: 'test'</li>
</ul></li>
<li>entry 2
<ul>
<li>field ID 1: 'test test'</li>
</ul></li>
</ul>

<p>I want to end up with <code>array('test', 'test test')</code>.
I now iterate through all content from the content table to check the field's handle against the handle of the field I'm looking for, but there must be a better way.</p>

<p>See <a href="https://github.com/nilsenpaul/nptypeahead/blob/master/nptypeahead/services/NpTypeAhead_DataService.php" rel="nofollow">this service</a> to see what code I use now.</p>

CC BY-SA 3.0
2015-02-04T14:37:57.760Z
Hey Paul - can you post the code you are using to iterate through all the content? Are you running a SQL query?
Aaron Berkowitz
CC BY-SA 3.0
2015-02-04T14:51:30.293Z
I did. I posted a link to the service on Github.
Paul
CC BY-SA 3.0
2015-02-05T02:51:03.930Z
I've been messing around throughout the day with fancy nested SQL queries to try and simplify your service algorithm, but couldn't get anything to work...yet!
Aaron Berkowitz
<plugin-development><fieldtypes>
What's the best way to get all content for a field?
# What's the best way to get all content for a field?

(Asked by: username_0 on 2015-02-04)

Given an array of field IDs, I want to get all content for those fields.
So, in this situation:

* entry 1
  + field ID 1: 'test'
* entry 2
  + field ID 1: 'test test'

I want to end up with `array('test', 'test test')`.
I now iterate through all content from the content table to check the field's handle against the handle of the field I'm looking for, but there must be a better way.

See [this service](https://github.com/nilsenpaul/nptypeahead/blob/master/nptypeahead/services/NpTypeAhead_DataService.php) to see what code I use now.

**Tags:** plugin-development, fieldtypes

> **Comments:**
> **username_1**: Hey username_0 - can you post the code you are using to iterate through all the content? Are you running a SQL query?  
> **username_0**: I did. I posted a link to the service on Github.  
> **username_1**: I've been messing around throughout the day with fancy nested SQL queries to try and simplify your service algorithm, but couldn't get anything to work...yet!  

---

## 0 answers

