From e9e349c27094c01aa288992f1b961bf0040d8db2 Mon Sep 17 00:00:00 2001 From: Ryan McCahan Date: Mon, 22 Apr 2019 10:22:35 -0600 Subject: [PATCH] Initial version --- README.md | 8 ++++++ lgnd-expire-stickies.php | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 README.md create mode 100644 lgnd-expire-stickies.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..22c0c42 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# LGND Expire Sticky Posts +This plugin automatically expires sticky posts after a set number of days (by default, 14). To use: + +- Edit the `lgnd-expire-stickies.php` file to set the appropriate value of `LGND_EXPIRE_STICKIES_DAYS` +- Install the plugin by uploading it to the Plugins page in your WordPress backend +- Activate the plugin + +Once installed and activated, the plugin will run using wp-cron **hourly**, selecting all sticky posts older than `LGND_EXPIRE_STICKIES_DAYS` and unstickying them. diff --git a/lgnd-expire-stickies.php b/lgnd-expire-stickies.php new file mode 100644 index 0000000..20675b0 --- /dev/null +++ b/lgnd-expire-stickies.php @@ -0,0 +1,54 @@ + -1, + 'post__in' => get_option('sticky_posts'), + 'date_query' => [ + [ + 'before' => [ + 'year' => date('Y', $before), + 'month' => date('m', $before), + 'day' => date('d', $before) + ] + ] + ] + ]; + $query = new WP_Query($args); + + while ($query->have_posts()) + { + $query->the_post(); + unstick_post(get_the_ID()); + } + wp_reset_postdata(); +} +add_action('lgnd_expire_stickies', 'lgndExpireStickiesCron');