doomm4711 2015-10-08 06:07
浏览 19

在上传图片时安排wordpress帖子

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;

        }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么