Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Usually when I create some form of query, I use an array for my arguments like this:

$postslistArgs = array( 
    'child_of' => 320,
    'parent' => 320
);                          
$postslist = get_pages($postslistArgs);

There are other times, however, when I need/want to use URI-style query parameters like this:

get_pages('child_of=320&parent=320');

That's all straightforward, but is there any way possible to use the URI parameter style on more advance union/intersection queries such as post__not_in that require an array of IDs?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

WP_Query uses PHP's native parse_str function, which uses the following structure to denote arrays:

'post__not_in[]=1&post__not_in[]=2&post__not_in[]=3'

is the same as

array(
  'post__not_in' => array( 1,2,3 )
)
share|improve this answer
    
That's awesome! Thanks so much for that. –  Dan Gayle Aug 14 '10 at 16:29
    
Wow, never knew this is possible. Thought some stuff is array-only. –  Rarst Sep 27 '10 at 6:14
    
Yeah, it should be noted that this will only work for values for which WordPress' class WP will take an array. So, for example, even though you can pass an array of post types to WP_Query, you can't send an array of post types through the url; WordPress doesn't understand the request, since WP expects a string value only. I think there's a patch that fixes this in 3.1, although I'd have to double check on that. –  John P Bloch Sep 27 '10 at 12:28

Your Answer

 
discard

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.