[wp-hackers] is it a good idea to remove the category base?
mikeschinkel at newclarity.net
Thu Dec 8 02:04:56 UTC 2011
> I'm wondering how does wordpress match the current URL? What look up
> does it do?
> Is it something like
> select current url from ?? where where url is a category?
No. WordPress uses an array of regular expressions (typically about ~75 entries for a new site) to match the incoming URL against and when matched the associated pattern is applied. Here is a dump of what the array looks like for a vanilla site:
When it finds a match from the regex on the left side it uses the pattern on the right side to populate keys and values in the global $wp_query->query_vars, and that is primarily what WordPress uses to figure out what page to generate.
> And if we had the category base in there, would that SQL query be more
> efficient? Hard to tell. It's still confusing to me...
It has nothing to do with SQL efficiency, it has to do with making sure URLs are unambiguous.
> Did they just not care about it and leave it upto a plug in to take
> care of it? Is this conclusion final?
You yourself explained the problem here:
> It would not matter if you also had a page called /USA. That page
> would never be accessible in this circumstance. So when you remove the
> cat base, be careful with your page names!
If they allowed removal of categories in WordPress core then they'd have to deal with the UX issues that would arrive if something created a category and a page with the same slug.
> And if so, what plugin do you recommend that does this ( the removal ) right?
I wrote such a plugin for a friend the other day as an exercise to show her how to do it. It ignores the rewrite array and just checks to see if the first segment matches a category and if so changes $wp_query->query_vars so WordPress will load the category archive:
Hope this helps.
P.S. A pre-emptive comment: I believe some other plugins do use the rewrite array but IMO they are a lot more complicated then they need to be though that's only my opinion and I'm sure at least one person on this list, who I can name but I won't, will take issue with my approach.
More information about the wp-hackers