The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to do cron Job in WordPress?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #149397

    I m working to randomize all the posts every day (as the date changes) by itself, and I have created a function that shuffles and returns the random post ids which I can use to show random posts.
    Anyways, all I want is to schedule this function to execute everyday at 12:00.
    I was preferring to use wordpress default function wp_schedule_event(); however that doesn’t seem to work. Has anyone worked on it before ? and know how to make it work? This is what I have used.

    add_filter('cron_schedules', 'my_additional_schedules'); 
    function my_additional_schedules($schedules) {
        // interval in seconds just to test if it is working
        $schedules['every2min'] = array('interval' => 2*60, 'display' => 'Every two minutes');
        return $schedules;
    // schedules the wp_cron_testing
    if( !wp_next_scheduled( 'wp_cron_testing' ) ) {
       wp_schedule_event( time(), 'every2min', 'wp_cron_testing' );
    add_action( 'wp_cron_testing', 'the_wp_cron_test' );
    function the_wp_cron_test() {
        echo  "Here I have my code that needs to be execute.";




Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Other’ is closed to new topics and replies.