Support

Account

Home Forums General Issues Update 'Message' field manually in PHP Reply To: Update 'Message' field manually in PHP

  • Missed the ACF Pro update. So I see its not using postmeta anymore…

    Here’s the updated code for anyone thats looking.

    function update_message_field($field_key='', $message='')
    {
    	global $wpdb;
    
    	$table = $wpdb->prefix.'posts';
    	$field = $wpdb->get_results("SELECT * FROM $table WHERE post_name = '$field_key' AND post_type='acf-field'");
    	if($field)
    	{
    		$meta = unserialize($field[0]->post_content);
    		$meta['message'] = $message;
    		$wpdb->update(
    			$table,
    			array(
    				'post_content'=>serialize($meta)
    			),
    			array('post_name'=>$field_key, 'post_type'=>'acf-field'),
    			array('%s')
    		);
    	}
    }