plugins – Running a function using Crown WordPress on one day a week, for example, Mondays of every week


Hello friends

I am trying to write a plugin to be able to publish a post on a specific day.
I need to be able to publish a specific text as a post on Mondays every week.
The searches I did on the Internet
I found a code (thanks to its author) that can publish a post at certain times in seconds.
It means one minute 60 seconds and one hour 3600 seconds
Can you help me determine the day?
For example, execute the function on Monday at 13:00 , publish a post
Thank you for your guidance

function bf_add_custom_schedule( $schedules )
    $schedules[ 'every_thirty_seconds' ] = array(
        'interval' => 30,
        'display'  => 'Every 30 seconds',
    return $schedules;
function bf_schedule_custom_event()
    add_filter( 'cron_schedules', 'bf_add_custom_schedule' );

    if( !wp_next_scheduled( 'bf_your_custom_event' ) )
        wp_schedule_event( time(), 'every_thirty_seconds', 'bf_your_custom_event' );
add_action( 'init', 'bf_schedule_custom_event' );

// fire custom event

function bf_do_something_on_schedule()
    $args = [
        'post_title' => 'Post by wp cron every 3 seconds',
        'post_content' => 'text',
        'post_status' => 'publish'


add_action( 'bf_your_custom_event', 'bf_do_something_on_schedule' );

Fardad Farhang 1 week 2023-01-22T08:14:54-05:00 0 Answers 0 views 0

Leave an answer