Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
    
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 '13 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 '13 at 4:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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