skip to Main Content

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.

2

Answers


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

    Login or Signup to reply.
  2. 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();
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search