iSS
iSS

Reputation: 2668

WordPress : Change %post_id% in permalink by a constant. Possible ?

I had an assignment of moving Joomla 1.0 content, categories and other stuff to the latest WordPress. Everything went fine, a few PHP scripts, a bit of fiddling with MySQL. But then, unexpected problem arose. I have to change permalinks to that:

$sitename/content/view/$post_id/$menu_id

The variables are from Joomla, and they have nothing to do with WordPress. I solved $menu_id thing through post_name in DB. But now I have to change the $post_id too, because it is exactly shifted by 44 (42'd be better though :) due to categories added first.

So finally the question: can I somehow subtract 44 from the %post_id% I have in my permalink settings? (sth like "content/view/(%post_id% - 44)/") Or maybe a small change in the WordPress code?

Thank you.

Upvotes: 0

Views: 214

Answers (1)

Agate
Agate

Reputation: 3232

I don't see any easy way to do what you want (apart from hacking Wordpress core which is not, IMHO, a good idea).

If you use an Apache webserver and if you don't have thousands of posts, you could write a bunch of apache rewrite rules (either in an .htaccess file or in your virtualhost file) to handle this redirection for you. A solution for a similar - but, I must admit, simpler - problem is described in this post.

Even with that solution (or hacking wordpress core), you'll face other problems, such as:

  • What if a user request a post ID between 1 and 44 ?
  • How will you display post permalinks ? You will have to add 44 to post ID when you display a post permalink, so that that amount can be substracted afterwards by your hack and redirect to the good post.

This is what come to my mind now, but I'm almost sure there will be other side-effects if you go this way because IDs are used litteraly everywhere.

It it is possible for you, I strongly suggest you do your migration process again, and keep IDs consistents with your old database. Even if it takes some times, it will really, really be easier to deal with and maintain.

Upvotes: 1

Related Questions