README for custom WP_Query is incorrect
njbarrett opened this issue · comments
I defined the following route:
Routes::map('category/:category/:subcategory', function($params) {
$category = $params['category'];
$subcategory = $params['subcategory'];
$query = new \WP_Query(array(
'post_type' => 'post',
'category_name' => $category,
'tax_query' => array(
array(
'taxonomy' => 'secondary_category',
'field' => 'slug',
'terms' => $subcategory,
),
),
));
Routes::load('archive.php', array('category' => $category, 'subcategory' => $subcategory), $query);
});
But I get the error:
Warning: parse_str() expects parameter 1 to be string, object given in /upstatement/routes/Routes.php on line 139
In fact you just need to pass the arguments array, not a WP_Query object:
Routes::map('category/:category/:subcategory', function($params) {
$category = $params['category'];
$subcategory = $params['subcategory'];
$query = array(
'post_type' => 'post',
'category_name' => $category,
'tax_query' => array(
array(
'taxonomy' => 'secondary_category',
'field' => 'slug',
'terms' => $subcategory,
),
),
);
Routes::load('archive.php', array('category' => $category, 'subcategory' => $subcategory), $query);
});
You are a scholar and a gentleman. This was killing me.