Answer the question
In order to leave comments, you need to log in
How to remove all product images by product id?
There is a store on wp and you need to remove all pictures for some products.
$post_thumbnail_id = get_post_thumbnail_id( (int)27923 );
//хочу получить аррей, а возвращает только один id, их там больше в галереи товара
//foreach($post_thumbnail_id as $id){
$res = wp_delete_attachment( $post_thumbnail_id, true );
// удаляет только одну, а нужно для всех
//}
Answer the question
In order to leave comments, you need to log in
Let's start with the fact that you don't need to do this - ( (int)27923 )
And here's a function for you that will return a list of all the images in the post.
function getAttachmentsPost($post_id = 0) {
$args = array(
'post_parent' => $post_id,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1,
);
if ( $attachments = get_children( $args ) ) {
return $attachments;
}
return [];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question