我尝试了以下几种方法:
当一个产品页面被删除(永久)时,它也应该删除贴在帖子上的:产品图库和产品图像。
我尝试了我在https://wordpress.stackexchange.com/questions/109793/delete-associated-media-upon-page-deletion上找到的解决方案
但这对我来说并不管用。
发布于 2014-07-10 22:13:01
您可以尝试以下操作:
add_action('after_delete_post','wdm_delete_post_images',10,1);
function wdm_delete_post_images($post_id)
{
$featured_image_id = get_post_meta($post_id,'_thumbnail_id',true);
$image_galleries_id = get_post_meta($post_id,'_product_image_gallery',true);
if(!empty($featured_image_id))
{
wp_delete_post($featured_image_id);
}
if(!empty($image_galleries_id))
{
$image_galleries_array = split(',',$image_galleries_id);
foreach($image_galleries_array as $single_image_id)
{
wp_delete_post($single_image_id);
}
}
}当产品被永久删除时,这将删除图像。
https://stackoverflow.com/questions/24676547
复制相似问题