0

I am having a unmanaged VPS, where my wordpress site is hosted, I am also using WP-ROBOT 3 plugin for auto posting, I want it to do auto post through cron jobs, According to the documentation of the plugin, I entered this code through SSH command wget --post-data='mincamp=2&maxcamp=3&chance=50' -O /dev/null http://myURL/ and it worked, but I want to set regular intervals, so that it autoposts everyday, how to do that? I want it to post after every 6 hours, what should be the cron commands

1
  • Can anyone help me in this? Commented Mar 11, 2011 at 5:08

1 Answer 1

3

You can do this via wp_cron by using the following,

function more_reccurences() {
return array(
    'sixhourly' => array('interval' => 21600, 'display' => 'Every 6 hours'),
);
}
add_filter('cron_schedules', 'more_reccurences');

then find the function that does the autopost and call it by

if ( !wp_next_scheduled('autopost_function') ) {
wp_schedule_event(time(), 'sixhourly', 'autopost_function');
}

If you want to use linux cron should be something like: * 6,12,18,24 * * * /some-command

-new edit: 28-3-2011

I think things are getting mixed up here, let me clarify. This * 6,12,18,24 * * * /some-command goes into your crontab file, which is completely outside your webserver and wordpress. This cannot be used in php.

If you want to schedule it in wordpress you will need the functions that I gave. I'm not very familiar with wp-robot but i can give try to help. wp-robot is premium so I cant check the code.

the code I gave at the top executes the autopost function every six hours. You need to write the autopost_function yourself or find a function in wp-robot you can trigger.

ill give some examples:

example ssh command:

function autopost_function() {
$cmd = escapeshellcmd('wget --post-data='mincamp=2&maxcamp=3&chance=50' -O /dev/null http://myURL/');
  exec ($cmd);
}

Please note that using exec() is considered very dangerous in PHP, if not done correctly your entire server can be compromised/hacked and it may not run correctly if your server is running in safe-mode. You could try opening the page with curl which would better but your server would need curl support.

Instead of the above I would use the following function to add posts programmatically. But this has nothing to do with wp-robot.

example wp function:

    function autopost_function() {
// Create post object
  $my_post = array(
     'post_title' => 'My post',
     'post_content' => 'This is my post.',
     'post_status' => 'publish',
     'post_author' => 1,
     'post_category' => array(8,39)
  );

// Insert the post into the database
  wp_insert_post( $my_post );
}

this function simply adds a post to the database, you can pass a lot of parameters to it. Look up wp_insert_post() on the codex for more information. Doing it like this is much safer, and easier.

You can use the above code outside wp-robot, so you wont have to change the core files. All examples I have written are untested so they might contain some syntax problems. Hope this helps get you going.

10
  • @Patriek I want to use Linux Cron, I mean to say that anyhow I want to start the auto posting, the php function which you provided, if I enter that, then will the auto posting start? Commented Mar 27, 2011 at 12:03
  • for the linux cron its * 6,12,18,24 * * * /your-command, you should put this in your cron schedule files. read more here adminschoice.com/crontab-quick-reference. The php functions are for wordpress cron, which is complete different you can ignore that if you want to use linux cron
    – Patriek
    Commented Mar 27, 2011 at 12:08
  • @Patriek where to write the function in wp-cron file? I mean before die(); or after that? and where to write if condition which you mentioned? after this function? Commented Mar 28, 2011 at 7:08
  • @Patriek hey this is OK, I want to adopt the wp-cron.php file method for setting the cron intervals, my question is the function more_reccurences() { and the if condition if ( !wp_next_scheduled('autopost_function') ) { where this code has to be entered in wp-cron.php file? Commented Mar 28, 2011 at 10:29
  • Dont alter the wp-cron file, best way to include is to write a simple one page plugin. It might work from your theme's functions.php but not sure if that works you can try it.
    – Patriek
    Commented Mar 28, 2011 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.