Simon
Simon

Reputation: 59

$wpdb>update having no effect on database?

I am trying to update a meta_value in the database for a specific meta_id using the $wpdb>update function but it doesn't change anything when its executed.

Here is the code.

<?php

// ID = 10074

global $wpdb;
$meta_value = 'NEW_VALUE';
$meta_key = 'wpcf-vehicle-status';
$meta_id = '10074';

$wpdb->update( 

 'wp25_postmeta', 
    array( 
     'meta_value' => $meta_value,
     'meta_key' => $meta_key
     ),
   array( 'ID' => $meta_id )

   );

   ?>

Any advice or help would be much appreciated.

Thanks

Upvotes: 1

Views: 252

Answers (2)

Simon
Simon

Reputation: 59

I have found another function called ' update_post_meta ' which seems to be working. Thanks for you input.

Upvotes: 0

Sourabh Matolia
Sourabh Matolia

Reputation: 169

There are couple of issues here:

1) There is no field "ID" in "wp_postmeta" table. It should be "meta_id" OR "post_id".
2) Table name should be in this format:

$wpdb->prefix."postmeta"

Here's the code after fixing TWO issues:

<?php

// ID = 10074

global $wpdb;
$meta_value = 'NEW_VALUE';
$meta_key = 'wpcf-vehicle-status';
$meta_id = '10074';

$wpdb->update( 

    $wpdb->prefix."postmeta", 
    array( 
        'meta_value' => $meta_value,
        'meta_key' => $meta_key
    ),
    array( 'meta_id' => $meta_id )

);

?>

Upvotes: 1

Related Questions