Last active
March 7, 2022 11:13
-
-
Save Oscar-Abad-Folgueira/8df5eac2f927d84c4b0d956e63b30540 to your computer and use it in GitHub Desktop.
WordPress Snippet: Como crear tareas programadas en WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @snippet WordPress Snippet: Como crear tareas programadas en WordPress | |
* @author Oscar Abad Folgueira | |
* @author_url https://www.oscarabadfolgueira.com | |
* @snippet_url https://www.oscarabadfolgueira.com/como-crear-tareas-programadas-en-wordpress--cron-jobs/ | |
*/ | |
add_action('cron_borrar_todos_posts', 'oaf_borrar_todos_posts'); | |
if (! wp_next_scheduled('cron_borrar_todos_posts')) { | |
wp_schedule_event((strtotime('24:00:00')), 'daily', 'cron_borrar_todos_posts'); | |
} | |
function oaf_borrar_todos_posts(){ | |
$todos_posts = get_posts( array('post_type'=>'post','numberposts'=>-1) ); | |
foreach ($todos_posts as $unpost) { | |
wp_delete_post( $todos_posts->ID, true ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment