WordPress在特定页面上执行特定的cronjob

发布于 2025-02-06 23:37:57 字数 370 浏览 1 评论 0原文

我有一个小型旅行页面,该页面使用内置的Cron Jobs(WP-Cron)每4小时通过API同步巡回演出和会议,直到这里一切都是完美的。

现在,我现在要实现的目标是,在特定页面上时,我也要“有力”执行此特定的cronjob(无论如何),例如,谢谢您的页面(不是wooCommerce)。

实现这一目标的最佳方法是什么?感谢您的一些专家帮助,谢谢。

I am having a small tour page that uses built-in cron jobs (wp-cron) to sync tours and sessions via an API every 4 hours and until here everything is perfect.

enter image description here

Now, what I am trying to achieve now is to also and "forcefully" execute this specific cronjob (regardless of it's schedule) when being on a specific page, e.g. Thank you page (not Woocommerce).

What's the best way to have this achieved? Some expert help would be greatly appreciated, thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愚人国度 2025-02-13 23:37:58

我一直怀疑,您是否使用服务器的本机CRON作业或WordPress的WP-Cron?

I have been left with the doubt, are you using the native Cron job of your server or the wp-cron of WordPress?

美人如玉 2025-02-13 23:37:57

我认为您可以使用Admin_Init钩子尝试尝试并检查页面ID或URL,然后运行执行函数。

add_action( 'travel_booking_do_tour_search_action', 'my_custom_cron_function');

function my_custom_cron_function(){
    // your execute action
}

add_action( 'admin_init', 'execute_cron_on_specific_page' );

function execute_cron_on_specific_page{
    if( is_page( 2094 ) ) // page_id = 2094 (eg:thank you page)
    {
        my_custom_cron_function();
    }
}

I think you can try by using admin_init hooks and check the page id or url then run the execute function.

add_action( 'travel_booking_do_tour_search_action', 'my_custom_cron_function');

function my_custom_cron_function(){
    // your execute action
}

add_action( 'admin_init', 'execute_cron_on_specific_page' );

function execute_cron_on_specific_page{
    if( is_page( 2094 ) ) // page_id = 2094 (eg:thank you page)
    {
        my_custom_cron_function();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文