我正在使用以下代码从上传的图像中自动发布帖子,它可以工作,但不会安排帖子发布,所有帖子都是在wordpress仪表板中的媒体上传器上传图像后立即发布的。
$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>\';
$theoriginaltitle = $attachment->post_title;
$onetitle = str_replace("-"," ",$theoriginaltitle);
$thetitlef = str_replace("_"," ",$onetitle);
$thetitle = ucwords(strtolower($thetitlef));
$cidargs = array( \'category_name\' => get_theme_mod( \'cat_1\' ) );
$cid = array( get_category_by_slug( $cidargs[\'category_name\'])->term_id );
$category_id = get_cat_ID( $cidargs[\'category_name\'] );
$category_link = get_category_link( $category_id );
$content = \'<strong>\'. $thetitle .\'</strong> is an <strong>HD wallpaper</strong> posted in <strong><a href="\'. esc_url( $category_link ).\'" target="_blank">\'.$cidargs[\'category_name\'].\'</a></strong> category. You can download <strong>\'. $thetitle .\'</strong> HD wallpaper for your desktop, notebook, tablet or phone or you can edit the image, resize, crop, frame it so that will fit on your device.<br />\';
$alltags = $thetitle;
$createtags = explode(" ", $alltags);
$postData = array(
\'post_title\' => $thetitle,
\'post_type\' => \'post\',
\'post_content\' => $content,
\'post_category\' => $cid,
\'tags_input\' => $createtags,
\'post_status\' => \'future\'
);
$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;
}
}
请帮助我更改此代码,以便安排帖子发布,每60分钟发布一篇帖子。