Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
Last active March 25, 2016 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodwardtw/888784031adfd1874bf6 to your computer and use it in GitHub Desktop.
Save woodwardtw/888784031adfd1874bf6 to your computer and use it in GitHub Desktop.
makes a weekly blog post from the contents of the curl'd page - triggered weekly by cron task
<?php
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>
<?php
function make_post (){
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://bionicteaching.com/tools/pinboard/index.php");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close ($curl);
$date = date_create('now');
$lastweek = date_sub($date, date_interval_create_from_date_string('7 days'));
$lastweek = date_format($date, 'Y-m-d');
$my_post = array(
'post_title' => 'Weekly Web Harvest for ' . $lastweek ,
'post_content' => $result,
'post_status' => 'draft',
'post_author' => 1,
'post_category' => array( 601 )
);
// Insert the post into the database
wp_insert_post( $my_post );
}
?>
<?php
make_post();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment