Skip to content

Commit

Permalink
Query: add new filter to allow setting custom number of years back (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeherve authored Aug 6, 2021
1 parent 04f003e commit a4f0e16
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion posts-on-this-day.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions src/class-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a4f0e16

Please sign in to comment.