Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Sayed Taqui on "How to get wordpress cron job function working?"

$
0
0

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 used WordPress 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 a test code I have used, m I doing something wrong?

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 execute.";
}

Viewing all articles
Browse latest Browse all 8245

Trending Articles