I’m trying to limit my WordPress search to a single, custom post type.
It seems I can change most parameters of the search query, except the post type variable.
$query_args = explode("&", $query_string);
$search_query = array();
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
}
$search_query['post_type'] = 'thread';
$search = new WP_Query($search_query);
This query will still return all post types. But if I set a different parameter, like ‘posts_per_page’, it works fine.
What’s going on? How can I limit my search query to a custom post type?
Thanks for your help!
EDIT: btw, I’m using WP 3.4.2
Place this in your
functions.php
file. 🙂Best!
R