Skip to content

Instantly share code, notes, and snippets.

@bigdawggi
Created February 3, 2015 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigdawggi/1d58d946bf2f00b34b9d to your computer and use it in GitHub Desktop.
Save bigdawggi/1d58d946bf2f00b34b9d to your computer and use it in GitHub Desktop.
Code to utilize the newly-created wp_cron schedule
// Add the action or social posts deleting
add_action( 'social_delete_posts', function() {
$args = array(
'post_type' => 'social_posts',
'post_status' => 'any',
'posts_per_page' => -1,
'date_query' => array(
array(
'column' => 'post_date_gmt',
'before' => '1 month ago',
),
),
);
$posts = get_posts($args);
foreach( $posts as $post ) {
$force_delete = true; // bypass trash
wp_delete_post( $post->ID, $force_delete );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment