I have the following code that works perfect on creating posts from images on uploading from wordpress dashboard by media uploads, but I need to schedule this posts at a specific interval (30 minutes one new post):
<?php
$autopost_controler = get_theme_mod( 'auto_onoff' );
if( $autopost_controler != '' ) {
switch ( $autopost_controler ) {
case 'on':
add_action('add_attachment', 'auto_post_on_image_upload');
function auto_post_on_image_upload($attachId)
{
$attachment = get_post($attachId);
$image = wp_get_attachment_image_src( $attachId, 'large');
$image_tag = '<p><img src="'.$image[0].'" /></p>';
$cidargs = array('category_name' => get_theme_mod('cat_1'));
$cid = array(get_category_by_slug($cidargs['category_name'])->term_id);
$theoriginaltitle = $attachment->post_title;
$onetitle = str_replace("-"," ",$theoriginaltitle);
$thetitlef = str_replace("_"," ",$onetitle);
$thetitle = ucwords(strtolower($thetitlef));
$content = '<strong>'. $thetitle .' </strong> is a funny photo posted in <strong>'.$cidargs['category_name'].'</strong> category. If you like <strong>'. $thetitle .'</strong> funny image, please share it with your friends.';
$alltags = $thetitle;
$createtags = explode(" ", $alltags);
$postData = array(
'post_title' => $thetitle,
'post_type' => 'post',
'post_content' => $content,
'post_category' => $cid,
'tags_input' => $createtags,
'post_status' => 'publish'
);
$post_id = wp_insert_post($postData);
// attach media to post
wp_update_post(array(
'ID' => $attachId,
'post_parent' => $post_id
));
set_post_thumbnail($post_id, $attachId);
return $attachId;
}
break;
case 'off':
break;
}
}