Making a new post from data from an external database
-
Hey guys.
So, we have a custom CMS in which writers we’ve hired write articles for clients of ours. We are tryint to take the content of those articles and publish them on our clients’ WP sites. At this point, this is a manual process and a real pain in the behind.
I’m trying making a custom plugin that pulls article data from our custom CMS and (what we want it to do is) creates a new post with the title, article, ad some other content to the client’s WP site. Ideally, we would install the plugin on our clients’ sites and it would then start to pull articles hourly (using a cron job plugin or something) from our in house CMS straight into our client’s sites as new posts.
I am having some trouble writing the plugin. I want to make it so that on activation, this plugin hits our CMS’ database and starts making new posts. I’m unsure as to what
Here is what I have so far (I am unsure as to what do to in the add_action() function/ how to do it).
<?php /** * @package New * @version 1.6 */ /* Plugin Name: CMS Plugin URI: Description: Practice Author: Moe Version: 1.0 Author URI: N/A */ function cms_db_connect(){ //global $wpdb; $cms_wpdb = new wpdb( 'ourdbusername', 'password', 'dbname', 'hostname'); $cms_wpdb->show_errors(); $sql = " SELECT * from articles as a INNER JOIN campaign_keyword as ck ON a.keyword_id = ck.keyword_id INNER JOIN client_campaigns as cc ON ck.campaign_id = cc.campaign_id INNER JOIN client_wp_credentials as cwp ON cc.client_id = cwp.client_id WHERE a.article_status = '5' LIMIT 3"; //die(print_r($sql)); $cms = $cms_wpdb->get_results($sql); foreach($cms as $key => $value){ $title = $key['title']; $author = $key['ordered_by']; $body = $key['richtext_body']; //doing some more stuff here } return $cms; } add_action('','cms_db_connect', 10, 2); /* */ ?>
- The topic ‘Making a new post from data from an external database’ is closed to new replies.