I had initially asked a question based on my code (which has since been removed), I need some help/guidance in creating a plugin.

Scenario: I have created a custom post type (CPT), now I need to insert values into the CPT from a database table external to the wp environment. This routine needs to run once every hour, no of rows can range from 50 - 500.

What is my best course of action?

Side question: Do I separate my CPT code from the insert routine code?

1 Answer 1


Use wp_cron to run a job every hour. http://codex.wordpress.org/Function_Reference/wp_cron Use $wpdb->get_results to fetch data from your external table. Example:

$q = "SELECT * FROM my_table";
$results = $wpdb->get_results($q, OBJECT);
foreach ( $results as $result) {

Insert new CPT-posts using wp_insert_post() http://codex.wordpress.org/Function_Reference/wp_insert_post

  • thanks windyjonas, will give it a try and let you know how i go, so in terms of best practice (first plugin here), should i split the code of CPT and the insert code? or keep them all together.
    – salted
    Jan 22, 2013 at 11:57
  • i never heard back from windyjonas however i will accept his response as the answer. thanks again windyjonas for you help.
    – salted
    Feb 11, 2013 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.