[wp-hackers] numeric slugs redux

Steve Taylor steve at sltaylor.co.uk
Thu Mar 31 12:34:22 UTC 2011


Hi,

There's a site for a major client, I built it a few years ago with
WordPress. They have a lot of conferences, and I based a lot of the
custom stuff on each year's conference having a page with the slug
being the year.

Last year, 3.0 broke the site. This is the ticket:

http://core.trac.wordpress.org/ticket/14238

I've had to hack the core (ew!) to keep the site working.

I've just fixed some terrible performance issues which were related to
the problem that Otto let everyone know about last year
(http://ottopress.com/2010/category-in-permalinks-considered-harmful/)
wherein categories at the start of permalinks is a no-no. I've changed
things so the year is at the start of the permalink.

Now, I've also upgraded to 3.1. I'm not sure if the new problem is
related to the year in the permalink or to 3.1. Anyway, the issue is
that any request to a conference landing page returns the content for
the parent page. For example this URL:

http://example.com/conferences/brazil/2011/

Will return the content for:

http://example.com/conferences/brazil/

This URL will return the content as normal:

http://example.com/conferences/brazil/2011/sub-page/

Obviously it's hitting a rewrite rule that's interferring. I'm not
very knowledgeable about the rewrites system, but poking around I
found a place where I could hook in and hack it. Here's what I've got:

add_action( 'parse_request', 'slt_parse_request' );
function slt_parse_request( $request ) {
	$pagename_parts = explode( '/', $request->query_vars['pagename'] );
	if ( $pagename_parts[0] == 'conferences' && preg_match(
'#/[0-9]{4,4}#', $request->query_vars['page'] ) ) {
		$request->query_vars['pagename'] .= $request->query_vars['page'];
		$request->query_vars['page'] = '';
	}
}

At some point the numeric slug at the end is being split off from the
request URI and placed in the 'page' request var.

So, some questions:

- Does anyone know if the above hack might cause others problems along the line?

- What's the difference between 'page' and 'pagename' in the query
vars? Might I be better off understanding the rewrites and adjusting
the rules?

- Are there any plans to properly address the issues with numeric
slugs in WP? I don't want to be spending time with every WP release
hacking this site to work properly. In the long run, am I looking at
having to recode the whole site to work without numeric slugs?

Many thanks for any input on this, it's causing a deal of stress for
the client and myself...

cheers,

Steve


More information about the wp-hackers mailing list