通过WP所有导入导入后,更新ACF图像的作者/用户



寻找解决方案以通过WP全部导入后分配帖子的所有子产品附件。图像进口商可以分配配置的用户,但是ACF文件字段并未遵循相同的逻辑,并根据登录的用户分配。

寻找解决方案以通过WP导入后分配帖子的所有子产品附件。

图像进口商可以分配配置的用户,但是ACF文件字段并未遵循相同的逻辑,并根据登录的用户分配。

我有一个用户安全层次结构,这意味着根据分配的作者锁定媒体。

我认为这将通过功能解决,只有我想弄清楚如何将其限制为特定的WP Imports

    <?php
// https://wordpress.stackexchange.com/questions/284283/how-can-i-change-an-images-author
add_action('pmxi_saved_post', 'image_author', 10, 1);
function image_author($id) 
{
$user_id = get_post_field ('post_author', $id);

$args = array(
'post_parent' => $id,
'post_type' => 'attachment'
//,
// 'post_mime_type' => 'image'
);
$attachments = get_posts($args);
if($attachments) :
    foreach ($attachments as $attachment) : setup_postdata($attachment);
       $the_post = array();
       $the_post['ID'] = $attachment->ID;
       $the_post['post_author'] = $user_id;
       wp_update_post( $the_post );
   endforeach;
endif;    
}
?>

最新更新