最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

posts - the wp_post_update isn't working all the time

programmeradmin8浏览0评论

When the user clicks on the preview I want to change the status of the post to "published" if not published and then reset my cache in my landing. Then after that, I want to revert the post status to the same stage. The last part of reverting to the same stage isn't working here is the code

add_filter( 'preview_post_link', function ( $link, \WP_Post $post )
{
    $slug = $post->post_name;
    $status_old = get_post_status($post->ID);
    if($status_old != "publish"){
//      return "/".$status_old;
        $post = array('ID'=>$post->ID, 'post_status' => "publish" );
        wp_update_post($post, true);
        $response = wp_remote_request(";);
        $post = array('ID'=>$post->ID, 'post_status' => $status_old );
//      $post = array('ID'=>$post->ID, 'post_status' => "draft" );
        wp_update_post($post, true);
    } else {
        $response = wp_remote_request(";);
    }
    return "mywebsite/".$slug;

 }, 10, 2 );
发布评论

评论列表(0)

  1. 暂无评论