简体   繁体   中英

Updating a wp_postmeta field not working in wordpress

I cannot update a wp_postmeta field called 'alive_days' and making its value equal to zero, in wordpress. I have tried all the two following solutions but still not working:

  1. $alive_days='alive_days';$mypostid=$_REQUEST['pid'];
  2. global $wpdb;
  3. $wpdb->query("update $wpdb->wp_postmeta set meta_value==\\"$ziro\\" where post_id=\\"$mypostid\\" and meta_key=\\"$alive_days\\"");
  1. $ziro=0;
  2. $mypostid=$_REQUEST['pid'];
  3. update_post_meta($mypostid, 'alive_days',$ziro);

The field value will not change after the execution.

Try This,

 $ziro=0; $alive_days = 'alive_days'; $mypostid = $_REQUEST['pid']; 
global $wpdb;
$wpdb->update( 
    'wp_postmeta', 
    array( 
        'meta_value' => $ziro,  
        'meta_key' => $alive_days   
    ), 
    array( 'ID' => $mypostid )

);

More Informations enter link description here

尝试使用此代码

update_post_meta( $post_id,'alive_days', 0 ); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM