Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
此 Cron 作业代码如何为您提供帮助?_创想鸟

此 Cron 作业代码如何为您提供帮助?

我已经使用 postype tvshows、seasons、episodes 为我的网站创建了此 cron 作业,它正确获取季节,然后生成它并发布,但是当其现有季节剧集的时间调用时,它不会生成和发布?有哪位好朋友能帮我解决这个问题吗?

`// 第 1 步:注册自定义一分钟间隔进行测试
add_filter(‘cron_schedules’, ‘custom_one_month_cron_schedule’);
函数 custom_one_month_cron_schedule($schedules) {
$schedules[‘every_month’] = array(
‘interval’ => 60, // 60 秒
‘display’ => __(‘每分钟’)
);
返回 $schedules;
}

// 第 2 步:安排 cron 作业每分钟运行一次(用于测试目的)
if (!wp_next_scheduled(‘auto_generate_new_seasons’)) {
wp_schedule_event(time(), ‘every_month’, ‘auto_generate_new_seasons’);
}

// 第 3 步:定义回调函数以生成新的季节和剧集
add_action(‘auto_generate_new_seasons’, ‘generate_new_seasons’);
函数generate_new_seasons() {
全局 $wpdb;

// query to get all tmdb ids of existing tv shows from post meta$tmdb_ids = $wpdb->get_col("select distinct meta_value from {$wpdb->postmeta} where meta_key = 'ids'");foreach ($tmdb_ids as $tmdb_id) {    // check if the tv show exists in the 'tvshows' custom post type    $tv_show_posts = get_posts(array(        'post_type' => 'tvshows',        'meta_key'  => 'ids',        'meta_value'=> $tmdb_id,        'posts_per_page' => 1,  // only need one result    ));    // if tv show does not exist, skip to the next tmdb id    if (empty($tv_show_posts)) {        continue;    }    // if the tv show is found, process it    foreach ($tv_show_posts as $post) {        // first, check if the 'clgnrt' meta is already set to avoid duplicate generation        $clgnrt = get_post_meta($post->id, 'clgnrt', true);        if (!$clgnrt) {            // set the 'clgnrt' meta to '1' for the tv show to avoid regenerating it            update_post_meta($post->id, 'clgnrt', '1');        }    }    // now check for and import new seasons for each tmdb id    $existing_seasons = $wpdb->get_col($wpdb->prepare(        "select meta_value from {$wpdb->postmeta} where post_id in (            select post_id from {$wpdb->postmeta} where meta_key = 'ids' and meta_value = %s        ) and meta_key = 'temporada'",        $tmdb_id    ));    $season = 1;    while ($season) {        // skip seasons that already exist (duplicate check)        if (in_array($season, $existing_seasons)) {            $season++;            continue;        }        // fetch season data from tmdb api        $response = wp_remote_get("https://api.themoviedb.org/3/tv/$tmdb_id/season/$season", array(            'body' => array(                'api_key' => 'your_tmdb_api_key',                'language' => 'en-us',                'append_to_response' => 'images'            )        ));        if (is_wp_error($response) || wp_remote_retrieve_response_code($response) != 200) {            break;        }        $json_tmdb = json_decode(wp_remote_retrieve_body($response), true);        // if no season data is found, break the loop        if (!isset($json_tmdb['season_number'])) {            break;        }        // create a new season post        $post_data = array(            'post_status'  => 'publish',            'post_title'   => $json_tmdb['name'] . ': season ' . $json_tmdb['season_number'], // season title: "show name: season 1"            'post_content' => $json_tmdb['overview'],            'post_type'    => 'seasons',        );        $post_id = wp_insert_post($post_data);        if (!is_wp_error($post_id)) {            // add meta data for the new season            add_post_meta($post_id, 'ids', $tmdb_id);            add_post_meta($post_id, 'temporada', $json_tmdb['season_number']);            add_post_meta($post_id, 'air_date', $json_tmdb['air_date']);            add_post_meta($post_id, 'dt_poster', $json_tmdb['poster_path']);            // update the 'clgnrt' meta for seasons to avoid regeneration            update_post_meta($post_id, 'clgnrt', '1');            // generate episodes for the new season            generate_episodes($tmdb_id, $season, $post_id);        }        $season++;    }}

}

// 第 4 步:生成一季的剧集
函数generate_episodes($tmdb_id, $season_number, $season_post_id) {
全局 $wpdb;

// check if the episodes for this season already exist$existing_episodes = $wpdb->get_col($wpdb->prepare(    "select meta_value from {$wpdb->postmeta} where post_id in (        select post_id from {$wpdb->postmeta} where meta_key = 'temporada' and meta_value = %s    ) and meta_key = 'episodio' ",    $season_number));$episode_number = 1;while ($episode_number) {    // skip episodes that already exist (duplicate check)    if (in_array($episode_number, $existing_episodes)) {        $episode_number++;        continue;    }    // fetch episode data from tmdb api    $response = wp_remote_get("https://api.themoviedb.org/3/tv/$tmdb_id/season/$season_number/episode/$episode_number", array(        'body' => array(            'api_key' => 'your_tmdb_api_key',            'language' => 'en-us',            'append_to_response' => 'images'        )    ));    if (is_wp_error($response) || wp_remote_retrieve_response_code($response) != 200) {        break;    }    $json_tmdb = json_decode(wp_remote_retrieve_body($response), true);    // if no episode data is found, break the loop    if (!isset($json_tmdb['episode_number'])) {        break;    }    // create a new episode post    $post_data = array(        'post_status'  => 'publish',        'post_title'   => $json_tmdb['name'] . ' ' . $season_number . 'x' . $episode_number, // episode title: "show name: 1x1"        'post_content' => $json_tmdb['overview'],        'post_type'    => 'episodes',    );    $episode_post_id = wp_insert_post($post_data);    if (!is_wp_error($episode_post_id)) {        // add meta data for the new episode        add_post_meta($episode_post_id, 'ids', $tmdb_id);        add_post_meta($episode_post_id, 'temporada', $season_number);        add_post_meta($episode_post_id, 'episodio', $json_tmdb['episode_number']);        add_post_meta($episode_post_id, 'air_date', $json_tmdb['air_date']);        add_post_meta($episode_post_id, 'dt_poster', $json_tmdb['still_path']);        // update the 'clgnrt' meta for episodes to avoid regeneration        update_post_meta($episode_post_id, 'clgnrt', '1');    }    $episode_number++;}

}

// 第 5 步:测试后清理并重置 cron 作业计划
add_action(‘init’, function() {
if (已定义(‘wp_debug’) && wp_debug) {
// 删除现有的 cron 计划以重置它
$timestamp = wp_next_scheduled(‘auto_generate_new_seasons’);
if ($timestamp) {
wp_unschedule_event($timestamp, ‘auto_generate_new_seasons’);
}
}

// Re-schedule the cron job to run hourly instead of every minute for productionif (!wp_next_scheduled('auto_generate_new_seasons')) {    wp_schedule_event(time(), 'hourly', 'auto_generate_new_seasons');}

});
`

以上就是此 Cron 作业代码如何为您提供帮助?的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1252283.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
PHP7和PHP8的社区支持情况
上一篇 2025年12月9日 23:52:24
如何使用 Traefik 在子文件夹中设置 Laravel
下一篇 2025年12月9日 23:53:22

相关推荐

  • 链路追踪(OpenTelemetry/Jaeger)集成

    要将opentelemetry和jaeger集成到java应用中,需按以下步骤操作:1.配置jaeger exporter,2.初始化opentelemetry,3.创建并管理span。通过这种方式,你可以有效地追踪和分析微服务间的调用链路,提升系统性能。 在现代微服务架构中,链路追踪已经成为诊断和…

    2026年9月21日
    000
  • Maingear电脑黑屏问题如何修复?专业级主机BIOS设置方法详尽

    Maingear电脑黑屏问题通常由BIOS设置、硬件接触不良或显示输出配置引起。首先应尝试进入BIOS,检查并调整显卡输出模式为PCIe/PEG,确保未误设为集成显卡;排查PCIe插槽模式兼容性,必要时切换为Gen3或Auto;若启动异常,可尝试切换UEFI/Legacy模式或恢复BIOS默认设置(…

    2026年9月21日
    000
  • 实测!Sora 2长视频优势大,Vidu Q2细节处理更胜一筹

    近日,AI视频工具领域的竞争愈发激烈。OpenAI推出的Sora 2刚刚登顶美区App Store榜单,国产新秀Vidu Q2便携重磅升级版本强势入局,引发广泛关注。不少从事自媒体创作与影视剪辑的朋友都在思考:这两款AI视频生成器,究竟谁更胜一筹?出于好奇,我亲自上手实测了一番,发现两者之间的差异更…

    用户投稿 2026年9月21日
    000
  • Java Stream 高效分组计数并获取Top N元素

    本文深入探讨了如何利用java stream api对数据进行高效的分组计数,并从中提取出现频率最高的top n元素。文章首先介绍了一种简洁的基于全排序的实现方式,该方法适用于数据集较小或top n值接近总数的情况。随后,针对大数据量和小型top n场景下的性能瓶颈,文章详细阐述了如何通过自定义`c…

    2026年9月21日
    000
  • mysql安装后如何优化配置文件

    答案:优化MySQL配置需先定位配置文件,再根据硬件和业务调整内存、InnoDB、连接等核心参数。具体包括设置innodb_buffer_pool_size为物理内存50%~70%,合理配置日志参数与连接数,启用慢查询日志,并使用工具辅助调优,避免过度配置,确保稳定高效。 MySQL 安装后,优化配…

    2026年9月21日
    000
  • mac怎么阻止特定app访问网络_Mac阻止应用访问网络方法

    可通过系统防火墙、hosts文件、第三方工具或pf防火墙阻止应用联网。首先,macOS内置防火墙可阻断入站连接,需在“系统设置-网络-防火墙”中添加应用并启用阻止;其次,编辑/etc/hosts文件,将目标域名指向127.0.0.1可屏蔽其网络访问,需刷新DNS缓存生效;再者,使用Little Sn…

    2026年9月21日
    000
  • VSCode的括号匹配功能如何自定义?

    可通过 settings.json 自定义括号高亮的边框和背景色;2. 用 editor.matchBrackets 控制是否启用高亮;3. 启用 bracketPairColorization 可为嵌套括号着色;4. 使用 Ctrl/Cmd + Shift + 快速跳转配对括号。 VSCode 的…

    2026年9月21日
    000
  • 马斯克xAI的Grok将推AI视频检测工具,能否破解深度伪造难题?

    随着ai视频生成技术飞速渗透网络,深度伪造内容不断扩散,网络信息真实性面临前所未有的挑战。在此背景下,马斯克的xai公司的grok模型即将推出一项关键升级,打造一款“真伪侦探”工具。 近日,马斯克在X平台回应网友担忧时表示,Grok即将获得识别AI生成视频并追踪其网络来源的能力,以此应对深度伪造内容…

    2026年9月21日
    000
  • AI推文助手如何生成节日祝福 AI推文助手的情感连接内容创作

    AI推文助手如何生成节日祝福 AI推文助手的情感连接内容创作AI推文助手如何生成节日祝福 AI推文助手的情感连接内容创作AI推文助手如何生成节日祝福 AI推文助手的情感连接内容创作AI推文助手如何生成节日祝福 AI推文助手的情感连接内容创作

    答案:通过AI推文助手的节日模板、情感关键词、用户数据定制和多语言混合策略,可高效生成个性化祝福,增强受众情感连接。 ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜ 如果您希望借助AI推文助手在节日期间传递温暖的祝福,同时增强与受众的情感连接…

    2026年9月21日 • 用户投稿
    000
  • 如何通过命令行参数启动VSCode?

    掌握VSCode命令行用法可提升开发效率,需先安装code命令到PATH,之后可用code .打开目录、code 文件名打开文件、code –diff比较文件、–disable-extensions排查问题,并支持别名与Shell结合使用。 通过命令行启动 VSCode 是一…

    2026年9月21日
    100
  • 万人同时在线抽奖活动架构

    万人同时在线抽奖活动的系统架构应采用微服务架构、分布式数据库、redis缓存、区块链存储结果,并使用负载均衡和异步处理技术。具体包括:1.采用微服务架构和分布式数据库(如tidb)保证系统稳定性和可扩展性;2.使用redis处理抽奖逻辑,确保高效和随机性;3.将结果存入区块链,保证透明度和可验证性;…

    2026年9月21日
    000
  • 小可AI小程序入口链接_小可AI小程序官方地址

    小可AI小程序官方入口为https://xcx.xiaokeai.com.cn,用户可在社交平台搜索使用;平台支持多轮对话、文本生成、图像理解及语音转文字功能,界面简洁、响应迅速,具备历史记录查看与持续优化的智能算法。 ☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepS…

    2026年9月21日
    000
  • Linux文件和目录管理常见命令

    Linux文件和目录管理依赖于ls、cd、mkdir、rm、cp、mv等核心命令,用于浏览、创建、删除、复制和移动文件与目录;通过find、du、grep等命令可查找文件、定位大文件并清理磁盘空间;使用rename、mmv或脚本可实现批量重命名;为安全起见,应谨慎使用rm命令,推荐结合-i选项或使用…

    2026年9月21日
    000
  • 大数据量下的批量导入/导出优化

    在大数据环境下优化批量导入/导出的方法包括:1. 使用批处理技术分批导入/导出数据,减少系统资源压力;2. 采用数据流技术如apache kafka进行实时处理,降低内存占用;3. 利用并行处理技术分配任务到多个处理器或节点,提高处理速度;4. 通过性能监控和调优识别并解决瓶颈点,以提升整体效率。 …

    2026年9月21日
    200
  • 《忍者龙剑传4》明日发售 制作人谈亮点:经典与创新并存!

    白金工作室今日迎来《忍者龙剑传4》(ninja gaiden 4)制作人兼导演中尾裕治的特别公告,正式确认游戏将于10月21日(周二)全球上线。中尾在声明中详细介绍了本作的核心特色,强调在传承系列精髓的同时注入全新机制,为玩家打造既怀旧又充满惊喜的忍者冒险。 特色一:传承与进化的战斗系统 系列经典操…

    2026年9月21日
    000
  • mysqlmysql如何优化in条件大列表查询

    使用EXPLAIN和慢查询日志判断IN性能问题,type为ALL且possible_keys为空或rows过大说明需优化;JOIN在有索引时通常优于IN,尤其当列表值来自另一表时;大IN列表可拆分为多个小IN结合UNION ALL,或存入临时表后用JOIN提升效率。 优化 MySQL 中 IN 条件…

    2026年9月21日
    000
  • 拍摄更强了!vivo X200系列功能升级:舞台模式双视野录像来了

    10月15日,vivo正式公布x200系列功能迭代计划,影像系统与相册体验将迎来多项重磅升级。 据悉,全新的希区柯克式Live Photo功能将支持主体智能追踪,用户可一键实现流畅变焦效果,该功能预计从11月起逐步推送。 舞台模式双视野录制功能将于12月陆续上线, 用户可一键启动前后双摄,录制视频时…

    2026年9月21日
    000
  • Linux怎么踢出指定的登录用户

    要踢出指定登录用户,首先使用w或who命令识别其TTY或会话ID,再通过pkill -KILL -t 强制终止会话,或用loginctl terminate-session 优雅结束;若需防止重新登录,可临时锁定账户(passwd -l)或将用户shell改为/sbin/nologin。 在Linu…

    2026年9月21日
    000
  • 何小鹏称飞行汽车市场份额将超汽车 家庭生活将巨变

    在10月16日启动的可持续全球领导者大会上,小鹏汽车创始人、董事长兼首席执行官何小鹏发表了主题演讲,深入阐述了公司在智能出行与人工智能技术方面的前沿战略。他透露,小鹏汽车预计将在2026年实现飞行汽车的量产,并坚信这一新兴领域的发展速度和市场潜力将远超传统汽车产业。 ☞☞☞AI 智能聊天, 问答助手…

    2026年9月21日
    000
  • iQOO 15开售:2K珠峰屏+自研Q3芯片 重塑手游视效新标杆

    iQOO 15开售:2K珠峰屏+自研Q3芯片 重塑手游视效新标杆iQOO 15开售:2K珠峰屏+自研Q3芯片 重塑手游视效新标杆iQOO 15开售:2K珠峰屏+自研Q3芯片 重塑手游视效新标杆iQOO 15开售:2K珠峰屏+自研Q3芯片 重塑手游视效新标杆

      备受瞩目的“未来性能旗舰”iqoo 15正式开售,起售价为4199元。作为iqoo推出的重磅力作,iqoo 15不仅延续了品牌一贯的硬核性能基因,更以“性能超长板,全面无短板”的产品理念,凭借第五代骁龙8至尊版、自研电竞芯片q3、2k三星珠峰屏、超级潜望长焦等顶级配置,全面刷新了高性能智能手机的…

    2026年9月21日 • 用户投稿
    100

发表回复

登录后才能评论
关注微信