Title: Using an array in query_posts
Last modified: August 20, 2016

---

# Using an array in query_posts

 *  Resolved [robahas](https://wordpress.org/support/users/robahas/)
 * (@robahas)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/using-an-array-in-query_posts/)
 * Hi – I am using the following to generate a list of posts that have certain tags:
 * `$query = array('cat' => '4', 'orderby' => 'rand', 'tag__in' => array(7,9))`
 * This works great.
 * The problem is that I can’t seem to generate the array for tag__in dynamically.
   If I use an array of values ( ‘tag__in’ => $array )it always outputs thus:
 * [tag__and] => Array ( [0] => 7,9 )
 * But the query wants only values separated by commas. Because of this it only 
   recognizes the first tag.
 * So how do I make an array only output comma separated values without keys? (PS
   I tried implode() and got the same result).
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Thread Starter [robahas](https://wordpress.org/support/users/robahas/)
 * (@robahas)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/using-an-array-in-query_posts/#post-3292626)
 * Here’s how I got it working:
 *     ```
       $tags = '1,2,3';
       $tags = explode(',',$tags);
       $post_query = array('cat' => '4', 'orderby' => 'rand', 'tag__in' => $tags );
       query_posts($post_query);
       ```
   
 * Here’s what $post_query looks like:
 * Array ( [cat] => 4 [orderby] => rand [tag__in] => Array ( [0] => 7 [1] => 9 ))
 * Maybe it will help someone.

Viewing 1 replies (of 1 total)

The topic ‘Using an array in query_posts’ is closed to new replies.

## Tags

 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)
 * [tag__in](https://wordpress.org/support/topic-tag/tag__in/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [robahas](https://wordpress.org/support/users/robahas/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/using-an-array-in-query_posts/#post-3292626)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
