wp_update_post() doesn’t update post_status

Question

First of all, I’ve already checked the solution for this question:
Why doesn't wp_update_post() update the post_status field?

I am having trouble with updating post_status of products and product_variations using wp_update_post(). This is the code:

function update_product_status($post_id) {
    wp_update_post(array(
        'ID' => $post_id,
        'post_status' => 'publish',
        'edit_date' => true,
        'post_date' => date('Y-m-d H:i:s'),
        'post_date_gmt' => gmdate('Y-m-d H:i:s')
    ));
    write_log('Restore trashed post with ID: ' . $post_id);
}

First, I look for trashed products and product variations based on multiple conditions. If all conditions match, I run the update_product_status() function with specified $post_id.

The function runs, the log is being updated with correct post IDs, but the post_status just stays ‘trash’ and it is not updated at all.

What am I doing wrong? I’ve added the edit_date, post_date and post_date_gmt arguments to wp_update_post, based on the answers from the other queston, but no luck.

0
Kristian Filo 3 months 0 Answers 8 views 0

Leave an answer