Upstatement / routes

Simple routing for WordPress
188 stars 38 forks source link

Query parameter not working with Wordpress 6 #39

Closed idflood closed 2 years ago

idflood commented 2 years ago

Hi, after updating Wordpress to 6 we noticed that the $query parameter is not working anymore.

Routes::map('some-test-page', function($params){
  $query = ['post_type' => 'custom-type'];
  Routes::load('my-template.php', $params, $query);
});

In the file my-template we were using something like $posts = (array) new Timber\PostQuery(); which was using this $query but it's not the case anymore.

jaybarry commented 2 years ago

I had the same issue and found that changing the parse request action from 'do_parse_request' to 'parse_request' on line 134 in Router.php seems to fix it.

idflood commented 2 years ago

Thanks @jaybarry , for reference I've found the wordpress changelog linked to this filter: https://make.wordpress.org/core/2022/04/27/changes-to-do_parse_request-filter-in-wordpress-6-0/

standerksen commented 2 years ago

I have the same problem, and @jaybarry's solution also fixed it for me. Hopefully this simple fix will be added to the official version soon.

jarednova commented 2 years ago

Thanks @standerksen @idflood @jaybarry — would love a PR to make this a part of the core code!

idflood commented 2 years ago

I'm just wondering if the parse_request is the best fix, without creating edge case and is backward compatible. It seems that another possibility would be to return TRUE instead of FALSE.

I will test both approach and create a merge request.

edit: Returning true doesn't work

jarednova commented 2 years ago

Thanks @idflood ! really appreciate the PR and the confirmation on approach. I've asked some others in Timber to review and test:

https://github.com/timber/timber/issues/2584

Will make sure we get this deployed asap!