我有更改附件图片标题(slug)但没有工作
function update_attachment($post_ID) {
$post=get_post($post_ID);
$old_name=$post->post_name;
$my_post = array(
'ID' => $post_ID,
'name' => $old_name."--".rand(1111,9999),
);
wp_update_post($my_post);
return $post_ID;
}
add_filter('add_attachment', 'update_attachment', 10, 2);
答案 0 :(得分:1)
请试试这个
function update_attachment($post_ID) {
$post=get_post($post_ID);
$old_name=$post->post_name;
global$wpdb;
$wpdb->query("update ".$wpdb->prefix."posts set post_name='".$old_name."-".rand(1111,9999)."' where ID='".$post_ID."'");
//var_dump($post_ID); exit;
return $post_ID;
}
add_filter('add_attachment', 'update_attachment', 10, 2);