# Querying Products in the Database

 In the process of building around Easy Digital Downloads you may find the need to query the database for product data. This document will show several examples of how to do that properly.

### Getting a Single Product

 The best way to get information about a single product is to use the EDD\_Download class. It accepts a `download_id` and returns an object with information about the download. Example:

```
$download = new EDD_Download( 109 );
```

 This would return an object like this:

```
EDD_Download Object
(
    [ID] =&gt; 109
    [price:EDD_Download:private] =&gt; 
    [prices:EDD_Download:private] =&gt; 
    [files:EDD_Download:private] =&gt; 
    [file_download_limit:EDD_Download:private] =&gt; 
    [type:EDD_Download:private] =&gt; 
    [bundled_downloads:EDD_Download:private] =&gt; 
    [sales:EDD_Download:private] =&gt; 
    [earnings:EDD_Download:private] =&gt; 
    [notes:EDD_Download:private] =&gt; 
    [sku:EDD_Download:private] =&gt; 
    [button_behavior:EDD_Download:private] =&gt; 
    [post_author] =&gt; 2
    [post_date] =&gt; 2016-03-22 13:30:29
    [post_date_gmt] =&gt; 2016-03-22 13:30:29
    [post_content] =&gt; Buy my mp3!
    [post_title] =&gt; My MP3
    [post_excerpt] =&gt; 
    [post_status] =&gt; publish
    [comment_status] =&gt; closed
    [ping_status] =&gt; closed
    [post_password] =&gt; 
    [post_name] =&gt; my-mp3
    [to_ping] =&gt; 
    [pinged] =&gt; 
    [post_modified] =&gt; 2016-03-22 13:30:29
    [post_modified_gmt] =&gt; 2016-03-22 13:30:29
    [post_content_filtered] =&gt; 
    [post_parent] =&gt; 0
    [guid] =&gt; https://edd.dev/?post_type=download&amp;p=109
    [menu_order] =&gt; 0
    [post_mime_type] =&gt; 
    [comment_count] =&gt; 0
    [filter] =&gt; raw
    [post_type] =&gt; download
)
```

 Once you have the object there are a wide variety of methods that can be run on it to get information like price, variations etc. [Full documentation for EDD\_Download here](https://easydigitaldownloads.com/docs/edd_download/).

### Getting Multiple Products

 Downloads are a WordPress custom content type, so it&#039;s possible to get the ids of multiple downloads using `get_posts()`. If you specify the fields parameter properly then get\_posts will get only the ids, and the query will be much faster. You&#039;ll also need to at least specify `download` for the post\_type. Example:

```
    $args = array(
        &#039;fields&#039;    =&gt; &#039;ids&#039;,
        &#039;post_type&#039; =&gt; &#039;download&#039;,
    );

    $downloads = get_posts( $args );
```

 You may use any option you wish in `get_posts()` to narrow your query. [Full documentation for `get_posts()` here](https://codex.wordpress.org/Template_Tags/get_posts).

 One additional option not found in the documentation for `get_posts()` is called `no_found_rows()`. This removes some data required for pagination, but dramatically speeds up your query. If you need pagination don&#039;t use this option. If you don&#039;t need pagination it would look like this:

```
$args = array(
	&#039;fields&#039;        =&gt; &#039;ids&#039;,
        &#039;post_type&#039;     =&gt; &#039;download&#039;,
	&#039;no_found_rows&#039; =&gt; true,
);

$downloads = get_posts( $args );
```

 The above query will return an array of download\_ids like this:

```
Array
(
    [0] =&gt; 109
    [1] =&gt; 82
    [2] =&gt; 79
    [3] =&gt; 61
    [4] =&gt; 42
)
```

### Working With Multiple Products

 Once you have an array of download\_ids you may simply iterate over the array creating EDD\_Download objects like this:

```
foreach ( $downloads as $key =&gt; $download_id ) {
	$download = new EDD_Download( $download_id );
	// do whatever you wish with each object
}
```