Nikhil Vaghela
Nikhil Vaghela

Reputation: 222

cron job in wordpress

I want to run a cron job in wordpress using the default function. I want set the time to run every 15 days. How can I set the the for this?

 function prefix_deactivation()
{
    wp_clear_scheduled_hook('prefix_hourly_event_hook');
}
register_deactivation_hook(__FILE__, 'prefix_deactivation');
function prefix_activation()
{
    wp_schedule_event(time(), 'everyminute', 'prefix_hourly_event_hook');
}
register_activation_hook(__FILE__, 'prefix_activation');

/* On activation, set a time, frequency and name of an action hook to be scheduled.  */
function prefix_do_this_hourly()
{
// do something every hour
    cronjob_options();
}
function cronjob_options()
{
    /* your job  */
}
add_action('prefix_hourly_event_hook', 'prefix_do_this_hourly');

Upvotes: 0

Views: 558

Answers (4)

Nikhil Vaghela
Nikhil Vaghela

Reputation: 222

<?php

     add_filter( 'cron_schedules', 'cron_add_day' );

     function cron_add_day( $schedules ) {
        $schedules = array(
            'day'     => array( 'interval' => 86400*1, 

                               'display' => __( 'Every Day' )
                             ),
        );
        return $schedules;
     }
    ?>

Upvotes: 1

user3213934
user3213934

Reputation:

Hope you will get perfact answer for cron job in wordpress

 <?php

     add_filter( 'cron_schedules', 'cron_add_everyday' );

     function cron_add_everyday( $schedules ) {
        // Adds once everyday to the existing schedules.
        $schedules = array(
            'everyday'     => array( 'interval' => 86400*1, 
             //set cron time you want call 86400 for 1 day  change 1 as per your days...
                                                       'display' => __( 'Every Day' )
                                                      ),
        );
        return $schedules;
     }
    ?>

Upvotes: 1

Ankur Bhadania
Ankur Bhadania

Reputation: 4148

try this code

add_filter( 'cron_schedules', 'cron_add' );

 function cron_add( $schedules ) {

    $schedules = array(
        'everyminute'     => array( 'interval' => 129600,  
                         'display' => __( 'Every Minute' )
                          ),
    );
    return $schedules;
 }

Upvotes: 1

Manish Jesani
Manish Jesani

Reputation: 1347

    add_filter( 'cron_schedules', 'cron_add_everyminute' );

 function cron_add_everyminute( $schedules ) {

    $schedules = array(
        'everyminute'     => array( 'interval' => 60*60*24*15,  
                                                   'display' => __( 'Every Minute' )
                                                  ),
    );
    return $schedules;
 }

Upvotes: 0

Related Questions