cron job to auto delete posts of a specific post type older than x days

// add the schedule event if it has been removed if( ! wp_next_scheduled( ‘mg_remove_old_entries’ ) ) { wp_schedule_event( time(), ‘daily’, ‘mg_remove_old_entries’ ); //run the event daily } // action hooked to fired with wordpress cron job add_action( ‘mg_remove_old_entries’, ‘mg_remove_old_entries’ ); function mg_remove_old_entries() { $posts = get_posts( [ ‘numberposts’ => -1, ‘post_type’ => ‘vfb_entry’, ‘date_query’ => … Read more

How do I get a Function in my functions.php to execute with a cron job?

When you use *nix cron to run a PHP file like that it won’t have WordPress loaded. You can load it manually, but a better method is to use WordPress’ own cron API. Schedule the event in your functions.php: if ( ! wp_next_scheduled( ‘expire_posts’ ) ) { wp_schedule_event( time(), ‘hourly’, ‘expire_posts’ ); } I’ve used … Read more

How do i schedule cron in wordpress for each second?

I do not think it is useful to have a cron running every second, but the function itself is quite simple. You add a filter to the cron_schedules: function f711_add_seconds( $schedules ) { $schedules[‘everysecond’] = array( ‘interval’ => 1, ‘display’ => __(‘Every Second’) ); return $schedules; } add_filter( ‘cron_schedules’, ‘f711_add_seconds’ ); You can now use … Read more

Sending out scheduled emails

You cannot rely on wp-cron for consistent results so you have to look to the server level. Most enterprise-level WordPress installations need some sort of consistent automation. This is how I automate WordPress in this type of situation. You will need to add a crontab to the server itself. If you’re running Linux, you can … Read more

WordPress cron running twice

I tried WP Crontrol instead and it turned out that two cron jobs were being created for generate_send_csv. To fix this, I created the crons within activation hooks and deactivation hooks as follows: register_activation_hook( __FILE__, ‘my_activation’ ); add_action( ‘generate_send_csv’, ‘generate_and_send_csv’ ); function my_activation() { wp_schedule_event(‘1488979800’, ‘daily’, ‘generate_send_csv’); } register_deactivation_hook( __FILE__, ‘my_deactivation’ ); function my_deactivation() { … Read more

Is there any background process that I can run from plugin without depending on page hits on a website without affecting page-load speed?

There is no reason for your design, but the core of your problem is that (I assume) people are trying to use a free tier of the API instead of properly paying for its use and removing the ridiculous restrictions. Anyway, the solution is fairly simple, run your cron every half an hour, allocate to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)