I have two fields in wp_posts table that wp_update_post() seems to be unable to change. I’m trying to use the following code:

$echo $group_access;
$echo $tag_list;
$my_post = array(
      'ID'           => 12095, 
      'post_title'   => 'Test Title',
      'post_content' => 'Test Content',     
      'group_access' => $group_access,
      'tag_list'     => $tag_list,
  );
// Update the post into the database
$post_id = wp_update_post( $my_post, true );

if (is_wp_error($post_id)) {
    $errors = $post_id->get_error_messages();
    foreach ($errors as $error) {
        echo $error;
    }
}

The $group_access and $tag_list variables echo the correct values. The post_title and post_content update correctly. group_access and tag_list do not update, and there is no error either.

Naturally, I’ve checked the table and group_access and tag_list are the correct column headers.

I’m baffled why it doesn’t work. Is wp_update_post() unable to change columns that are not part of the default WP install? Is it possibly a datatype thing (e.g. I should be passing an array or integer, but I’m passing a string)?

2 Answers
2

You are correct; WordPress will not update custom database columns using wp_update_post() or wp_insert_post(). Instead of creating custom database columns, consider using post meta and/or taxonomy APIs.

If you must altar the wp_posts table, you will need to update your custom columns on your own and you may run into issues with various other plugins who don’t take the custom database columns into account.

Leave a Reply

Your email address will not be published. Required fields are marked *