From a4f0e167617e8a84266997243e386fb9253ba492 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 6 Aug 2021 15:34:20 +0200 Subject: [PATCH] Query: add new filter to allow setting custom number of years back (#12) --- posts-on-this-day.php | 2 +- readme.txt | 8 ++++++-- src/class-query.php | 12 ++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/posts-on-this-day.php b/posts-on-this-day.php index 8dd8504..472f7d5 100644 --- a/posts-on-this-day.php +++ b/posts-on-this-day.php @@ -4,7 +4,7 @@ * Plugin URI: https://jeremy.hu/my-plugins/posts-on-this-day/ * Description: Widget to display a list of posts published "on this day" in years past. A good little bit of nostalgia for your blog. * Author: Jeremy Herve - * Version: 1.5.2 + * Version: 1.5.3 * Author URI: https://jeremy.hu * License: GPL2+ * Text Domain: posts-on-this-day diff --git a/readme.txt b/readme.txt index 7015e65..2d8a20b 100644 --- a/readme.txt +++ b/readme.txt @@ -1,10 +1,10 @@ === Posts On This Day === Contributors: jeherve Tags: widget, on this day -Stable tag: 1.5.2 +Stable tag: 1.5.3 Requires at least: 5.6 Requires PHP: 7.1 -Tested up to: 5.7 +Tested up to: 5.8 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -46,6 +46,10 @@ You have 2 ways to do so. == Changelog == +### [1.5.3] - 2021-08-06 + +* Query: create new filter to allow setting a custom amount of years to fetch posts. + ### [1.5.2] - 2021-04-15 * Caching: cache data until midnight of the same day, instead of caching it for 24 hours. diff --git a/src/class-query.php b/src/class-query.php index b757b7e..8780a6b 100644 --- a/src/class-query.php +++ b/src/class-query.php @@ -33,6 +33,18 @@ public function get_posts( array $instance ): array { $types = implode( '-', $instance['post_types'] ); $exact_match = ! empty( $instance['exact_match'] ) ? (bool) $instance['exact_match'] : false; + /** + * Filter the amount of years back to fetch posts from. + * + * Careful though; that can make for some really expensive queries, + * so could slow the first loading of the page where the widget is displayed once a day. + * + * @since 1.2.0 + * + * @param int $back Amount of years back to fetch posts from. + */ + $back = apply_filters( 'jeherve_posts_on_this_day_query_back', $back ); + /* * Let's attempt to cache data for a day * to avoid running an expensive WP_Query