Upstatement / routes

Simple routing for WordPress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query parameter not working with Wordpress 6

idflood opened this issue · comments

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.

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.

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/

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.

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

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

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

timber/timber#2584

Will make sure we get this deployed asap!