copy attachment title to description and alt text

You can make a query to loop through all the attachments, and then update the attachment info for each attachment in the while loop.

Something like

$args = array(
   'post_type' => 'attachments',
   'post_status' => 'any',
   'posts_per_page' => -1,
)

$query = new WP_Query($args)

if($query->have_posts()): 
while($query->have_posts()): $query->the_post();

// 1. Get the attachment filename here and store it in a variable eg. $filename. See comment at the end of this answer

// 2. Update the post title
$attachment_post = array(
   'ID' => get_the_id();
   'post_title' => $filename
)
wp_update_post($attachment_post);

endwhile; wp_reset_postdata(); endif;

Did a quick search on how to get the attachment filename but couldn’t find it but this should get you started. Within the loop you should also be able to update the description. You can look at wp_update_attachment_metadata and als check this post (related to the filename).

Leave a Comment