themosis / framework

The Themosis framework core.
https://framework.themosis.com/
GNU General Public License v2.0
671 stars 121 forks source link

Route conflicts #360

Closed kevinkiel closed 7 years ago

kevinkiel commented 7 years ago

I'm currently using "themosis/framework": "dev-master" (Version: 1.3.0)

I've registered a post type called 'location'

Now I add a custom post called amsterdam (/location/amsterdam). And I add a normal page called amsterdam (/amsterdam).

When I visited the page '/location/amsterdam' it redirects to the normal page '/amsterdam' and it ignores the custom post type route.

How is that possible?

We'eve figured out this happens before the route is being dispachted so it happens somewhere after the functions.php and before route dispatching. We we're hoping you could help us with this issue

This is what my route files looks like:

` Route::group(['namespace' => 'App\Controllers'], function() {

/**
 * Posttype: Location
 */
Route::get('singular', [LOCATION_POST_TYPE, 'uses' => 'LocationController@singular']);
Route::get('postTypeArchive', [LOCATION_POST_TYPE, 'uses' => 'LocationController@archive']);

/**
 * Route for the default page
 */
Route::get('front', 'PageController@front');

/**
 * Route for the default singular page
 */
Route::any('singular', 'PageController@singular');

}); `

jlambe commented 7 years ago

It is strange...

  1. Is your page route before the post type one? If yes, put it after.
  2. Did you flush the rewrite rules?

The routes are handled/dispatched against the template_redirect hook so all routing logic is happening before any WordPress template conditions is checked. As it is ran from an event, the functions.php file has been read entirely before the route is even dispatched. This is also why the routes can be registered before being processed.

Are you using the latest commit for the framework and latest commit from the theme? I see you set your own namespace where the default is Theme\Controllers for the routes.php file which is now loaded from a custom RoutingServiceProvider defined in the theme in place of being just required from the functions.php file.

Let me know how it goes. I'll test on my side using your location custom post type slug.

jlambe commented 7 years ago

I've just tested on a fresh installation. Indeed by default, it redirects to the page route. But after flushing the rewrite rules, it worked as expected. How it goes on your side?

Page: image

Location post type (singular): image

kevinkiel commented 7 years ago

@jlambe thanks for the reply. We changed the theme options with your last commits. And for new install this works good. :) For existing installation we still got the same issue.

An other question: When do you release a steady release? 👍 We would like to work with releases instead of dev-master.

jlambe commented 7 years ago

The date is not yet fixed but the release is coming right after the WordPress 4.7 release, so coming early january 2017.