I have developed a custom script that uses wp_insert_post
to create new posts, however i’d like to use similar code to create the same data in another wp database.
Could be this done on the fly before insertion? For example instruct wordpress to point another database and then insert data?
Or should I do this “manually” using raw mySQL code?
Leave a Reply
You must be logged in to post a comment.
You could avoid SQL altogether and use the XML-RPC API. This would also let you post to remote wordpress installs too.
( note if XML-RPC is not an option, scroll further down )
If Using XML-RPC
Here’s some code from a quick google search using XML-RPC to post to a remote WordPress blog:
http://en.forums.wordpress.com/topic/great-code-for-remote-posting?replies=5
Here’s a simpler set of examples with an explanation of the XML-RPC APIs
http://life.mysiteonline.org/archives/161-Automatic-Post-Creation-with-Wordpress,-PHP,-and-XML-RPC.html
And here’s an example from WP-Recipes using Curl and XML-RPC:
http://www.wprecipes.com/post-on-your-wordpress-blog-using-php
If afterall that XML-RPC is not for you
Perhaps a wordpress multisite might be best for you? Creating the new post would be as simple as calling
switch_to_blog($blog_id);
then doing your business creating the new post, before callingrestore_current_blog();
If you MUST use SQL
Use this question linked to by mike23 in order to gain access via a wpdb object