WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Slight problem, I have the following code:

$purchaseprodid = $_GET['ids'];
$args = array(
                  'post_type' => 'prizes',
                  'post__in' => array($purchaseprodid)

                while (have_posts()) : the_post(); 

I am getting comma seperated numbers for id's in a url, and they dont seem to be querying the posts. If I manually type the id's in they work no problem, but just not when using a variable $purchaseprodid.

Any ideas?


share|improve this question
up vote 2 down vote accepted

You need to explode the string you obtain from $_GET['ids'] into an array, at the moment you a parsing a to string post__in rather than an array of IDs.


$purchaseprodid = isset($_GET['ids']) ? explode(',',$_GET['ids']) : array();

However, you can sometimes run into difficulties using $_GET with WordPress, it's better to use the API provided and register your variable, see this question.

share|improve this answer
Thanks! That did it :) – JamesG Feb 23 '12 at 14:39

You can instead use the standard WordPress function wp_parse_id_list like this:

$purchaseprodid = isset( $_GET['ids'] ) ? wp_parse_id_list( $_GET['ids'] ) : array();

that checks that the input data is not already an array, clears duplicates and converts the type of each array element to integer.

More info at:


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.