wordpress 给旧文章按分类批量增加特色图

给旧文章按分类批量增加特色图

//分类特色图
function upload_image(){
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if(is_category('7'))//分类
{
if (!$already_has_thumb) {
set_post_thumbnail($post->ID, 27112);//媒体库图片
}
}
if(is_category('4'))
{
if (!$already_has_thumb) {
set_post_thumbnail($post->ID, 27117);
}
}
}
add_action('the_post', 'upload_image');
add_action('save_post', 'upload_image');
add_action('draft_to_publish', 'upload_image');
add_action('new_to_publish', 'upload_image');
add_action('pending_to_publish', 'upload_image');

没有账号? 忘记密码?

社交账号快速登录