Can't update CPT Fields using wp_update_post

I’m using the following array to update a CPT using wp_update_post() but the CPT fields are not updated. I’m not getting any errors.

$update_post = array(

‘ID’ => $post->ID,

‘post_title’ => $_POST,

‘plazo_de_renta’ => $_POST,

‘renta_mensual’ => $_POST,

);

  • Adam Czajczyk
    • Support Gorilla

    Hello Iker

    I hope you’re well today and thank you for your question!

    The “wp_update_post()” function takes either array or object as a first parameter. If it’s an array, there’s a direct relationship of the array elements and the column names in “wp_posts” table. If it’s an object, it must follow WP_Post object structure.

    In both cases, custom fields are not there. Custom fields are stored in a separate table as post meta data. Therefore, you should additionally use “update_post_meta()” function to update values of custom fields:

    https://codex.wordpress.org/Function_Reference/update_post_meta

    Best regards,

    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.