Home > database >  How to delete post item from db by Post id in wordpress
How to delete post item from db by Post id in wordpress

Time:04-19

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 ?

CodePudding user response:

You can delete post meta using delete_post_meta function.

forech($posts as $post){
    delete_post_meta($post->ID, 'profile_image');
}

CodePudding user response:

Wordpress function delete_post_meta

<?php delete_post_meta(76, 'my_key', 'Steve'); ?>
  • Related