dss89001 2018-08-25 04:00
浏览 35

WordPress会自动删除youtube已删除的视频

I have a website which imports videos automatically from Youtube. and I have used these codes in (single.php because it's not working in functions.php) to check if the video has been deleted then redirect the post to its category page

The post like this

<iframe width="560" height="315" src="https://www.youtube.com/embed/Videocode" frameborder="0"></iframe>

The Code

    //Check If Video Is Deleted
    global $post;
    global $wpdb;

    $categories = get_the_category($post->ID);
    $cat_link = get_category_link($categories[0]->cat_ID);

    the_post(); // necessary to use get_the_content()

    $links = [get_the_content(get_the_ID())];
    foreach($links as $link)
    preg_match("#([\/|\?|&]vi?[\/|=]|youtu\.be\/|embed\/)([a-zA-Z0-9_-]+)#", $link, $matches);
    //var_dump(end($matches));
    $key = (end($matches));

    $headers = get_headers('https://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v=' . $key);

    if(is_array($headers) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/',$headers[0]) : false){
    // video exists
    //echo 'found ID';

    } else {
    // video does not exist
    // Try to mark the post by meta value or tag but not work
    // update_post_meta(get_the_ID(),'deletedxxx','yes');
    //wp_set_post_terms( $post_id, 'deleted', $taxonomy );
    wp_redirect($cat_link,301); exit;
    }

I'm trying to mark the post by meta value or tag but not working!! I need two things

1-Mark the post by meta value because

A- (if it has this value stop check again on the video status).

B- (if it has this value redirect it to any post has any of its tags).

2-Remove this post from any loop at the theme

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决