I have been using WPML for the use of multilingual but I am having major issues with it and am tired of it.
I have now set up two WordPress set ups on two different domains. What I need to do is create a button / way of having an if statement that will take the user to the exact page / post / product in the different language?
For example
I am on a post about cars in English the use will use the drop down to German and get the exact post but in German.
Now I know I have written any code yet but I am just the in the process and wanted to ask here first to see if anyone could point me in the right direction. Could this be done in PHP or Javascript / jquery etc?
Thanks for any help,
Max.
2 Answers
When a user creates a new page/post/product on one site, use the XML-RPC API to create a matching one on the other site. Make sure to save the ID of the original post under a meta key for the “duplicate” post, and then use the response ID from the API to save the “duplicate” ID under a meta key for the original.
You’ll now have a post on each site with a reference to the other by ID, which will be enough to generate the “edit” link:
http://otherdomain.com/wp-admin/post.php?post=[ID]&action=edit
There are a few caveats worth bearing in mind – firstly, if a user deletes a post on one site, you lose the reference. It would be a good idea to hook onto the delete_post
action and either:
- Prevent the user from doing so (“this post is a translated version and cannot be deleted”)
- Use the XML-RPC API again to delete the reference from the other site.
Also, post authors. If you’re using a shared database with custom user tables (which is what I would recommend), you only have to ensure they have the same capabilities on both sites.
However, if the users are also duplicates (separate installs), you’ll need a similar cross-site reference (to know which author ID to use when creating the “other” post).