Created
October 15, 2018 11:40
-
-
Save markusvonplunkett/1ab016ee2a07150bc6dea28958ee3267 to your computer and use it in GitHub Desktop.
Rename media titles based on the woocommerce product name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rename_featured_images_to_post_title($post_type){ | |
$posts = get_posts(['post_type' => $post_type, 'posts_per_page' => -1]); | |
foreach($posts as $post){ | |
$title = $post->post_title; | |
$name = $post->post_name; | |
$thumbnail = get_post_thumbnail_id( $post ); | |
if((bool)$thumbnail){ | |
if(get_the_title($thumbnail) != $title){ | |
wp_update_post([ | |
'ID' => $thumbnail, | |
'post_title' => $title | |
]); | |
} | |
} | |
} | |
die(); | |
} | |
if(isset($_GET['rename_featured_images'])){ | |
rename_featured_images_to_post_title('product'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment