Query_posts $query_string

I have a query that looks like:

query_posts($query_string."&post_type=attachment&posts_per_page=9&paged=".$paged);

I’d like it to looks something like:

$args = array(
    'paged' => $paged,
    'posts_per_page' => 9,
    'post_type' => 'attachment'
);
query_posts($args);

I am trying to integrate $query_string into the query_posts with $args…can anyone point me in the right direction.

Thanks,
Josh

1 Answer
1

After some searching I found the parameters I needed: https://gist.github.com/luetkemj/2023628 (on Line 231)

//////Search Parameter
//http://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter
's' => $s,                              //(string) - Passes along the query string variable from a search. For example usage see: http://www.wprecipes.com/how-to-display-the-number-of-results-in-wordpress-search 
'exact' => true,                        //(bool) - flag to make it only match whole titles/posts - Default value is false. For more information see: https://gist.github.com/2023628#gistcomment-285118
'sentence' => true,                     //(bool) - flag to make it do a phrase search - Default value is false. For more information see: https://gist.github.com/2023628#gistcomment-285118

I added 's' => $s to my $args which passes along the query string, which is what I was looking for 🙂

My code now looks like:

$args = array(
    'paged' => $paged,
    'posts_per_page' => 9,
    'post_type' => 'attachment',
    's' => $s
);
query_posts($args);

Leave a Comment