'How to delete post item from db by Post id in wordpress
I am working with wordpress, I am getting following data in loop,"Id" is our "postid",And i want to delete only single attribute/key(profile_image) using that "postid",which i am getting in loop
Array
(
[id] => 46456
[status] => approved
[profile_image] => isProfile
)
Array
(
[id] => 46457
[status] => approved
[profile_image] => isProfile
)
Array
(
[id] => 46458
[status] => approved
[profile_image] => isProfile
)
Here is my code,How can i do this ?
foreach($datas as $data)
{
echo "<pre>";print_r($data);
delete_metadata( 'post', null, 'profile_image', '', true );
}
Where i am wrong ?
Solution 1:[1]
You can delete post meta using delete_post_meta function.
forech($posts as $post){
delete_post_meta($post->ID, 'profile_image');
}
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Code Lover |
| Solution 2 | kanojiakr |
