Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README for custom WP_Query is incorrect #7

Open
njbarrett opened this issue Nov 17, 2016 · 1 comment
Open

README for custom WP_Query is incorrect #7

njbarrett opened this issue Nov 17, 2016 · 1 comment

Comments

@njbarrett
Copy link

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);
});
@wisefool
Copy link

wisefool commented Jun 2, 2017

You are a scholar and a gentleman. This was killing me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants