length of post name in permalinks
-
Hi.
I’m in the process of trying to migrate from MT (on TypePad) to a WordPress installation (WP 1.5) .
The one problem I still have left, trying to make the old permalinks still working, is that TypePad shortened the name of individual posts, while WP puts the entire title in the URL.
So what I need is either a way to completly convert WP to a similar method of trimmed names (which is good since final URLs are shorter, but they’re also not as elegant, and I expect this would require more work), or a way to allow finding posts coming from the old URLs based on the first part of the name (which is what I’ve been trying to do so far, without success).
The concept seems simple enough. When searching for the post in WP the code will need to know it’s a special case of legacy URL (which will always be reached anyway through an .htaccess redirect, so I should be able to add a parameter to the query string), and change the database query to select a post based on year, month, and the first 15 characters of the name (which is unique in my case).
But I can’t seem to find the right places in WP PHP code to do that. After playing with url_to_postid, before the DB query (which I eventually realized doesn’t happen always, so is the wrong place) I so far came to the conclusion that the right place is the WP-Query->get_posts method. But I have no PHP/Apache experience, and can’t quite figure out how to check for URL query string parameters (I’ve add a special parameter to the URL through .htaccess redirect, but the $q variables doesn’t seem to hold it, despite the fact that as far as I see it’s supposed to hold everything). If I hard code an existing name into the $q[‘name’] variable before the SQL query, it works, but checking for my new parameters, or even simple checks for the length of the $q[‘name’] parameter, never does anything.
I tried to both redirect and just rewrite the URL explicitly, but none of these passed my ‘legacy’ parameter
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9a-zA-z\-]{1,15})\.html$ /blog/$1/$2/$3/?legacy=true [r=permanent,L]
#RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9a-zA-z\-]{1,15})\.html$ /blog/index.php?&legacy=true&year=$1&monthnum=$2&name=$3 [QSA,L]
Though both passed everything else properly.
in the get_posts method, if I do
$q[‘name’]= “made-up-post-name-that-exists”;
just for checking, it works, but if I try to put a changed DB query, when building the WHERE clause, inside
if (” != $q[‘legacy’]){}
it never gets called. Actually, even something like checking the strlen() on the $q[‘name’] parameter doesn’t trigger the if condition, when I know I send larger URLs than the condition I send for.So if anyone can tell me what am I missing, or if there’s a simpler way and I’m just barking up the wrong tree, I’d be grateful.
Plus, though that’s a different problem, which I should be able to sort out once I actually get to it, would it work later to just inside the SQL WHERE clause check for SUBSTRING(post_name,1,15) instead of post_name, or should I replace the = with a LIKE command instead?
Again, thank you very for any assistance you could provide, and I hope that I didn’t provide too much info on what I’ve been trying so far…
- The topic ‘length of post name in permalinks’ is closed to new replies.