1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

change timing of an automatic posting

Discussion in 'PHP' started by Neutron, Apr 10, 2013.

  1. #1
    I currently have a function (below) in one of my wordpress plugins that determines the time of the last post in my blog and then triggers the plugin to create a new post 1 day later. The calculation of time is rudimentary and is essentially represented in seconds as 24*60*60. However, this is not accurate and for some reason results in posts being up to 30 minutes shifted from the previous day's time of posting.

    Is there no solution to just modify it so that it posts at a set time each day? For instance at 11:00am everyday?

    function wpnhl_do_post(){
        $post_now = false;
        //get the last posted time
        $last_posted_time = (int) get_option('wpnhl_last_post');
        if($last_posted_time == 0){
            $post_now = true;
            $diff = time() - $last_posted_time;
            $one_day = 24 * 60 * 60;
            if($diff >= $one_day){
                $post_now = true;
        if($post_now == true){
            $cat = unserialize(get_option('wpnhl_cat'));
            $title = "NHL Injuries - ".date("F j, Y");
            $post = wpnhl_get_data();

    Solved! View solution.
    Neutron, Apr 10, 2013 IP
  2. #2
    I haven't creating something like this for Wordpress before but after a little searching I found a function that would help you.

    <?php wp_schedule_event($timestamp, $recurrence, $hook, $args); ?>
    URL: http://codex.wordpress.org/Function_Reference/wp_schedule_event

    Have a look at that it should help you to get started in running the required function at certain times.
    HuggyStudios, Apr 11, 2013 IP
    Neutron likes this.
  3. Neutron

    Neutron Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Awesome. Perfect. Done. Thanks.
    Neutron, Apr 11, 2013 IP