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) {
        '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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.