Make WordPress Core

Opened 3 weeks ago

Closed 13 days ago

#64304 closed enhancement (fixed)

Archives filters: add new filter to allow customizing the limit for the queries to fetch archives

Reported by: jeherve's profile jeherve Owned by: westonruter's profile westonruter
Milestone: 7.0 Priority: normal
Severity: minor Version: 1.2
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: performance Cc:

Description

wp_get_archives already comes with 2 filters allowing one to customize some of the aspects of the queries to fetch archives on a site:

  • getarchives_where allows you to customize the WHERE clause
  • getarchives_join allows you to customize the JOIN clause

I think it would be useful to add a new filter, to allow customizing the LIMIT clause as well. In some environments, with sites with lots of posts with longform content, some of those queries can be really resource-intensive.

Until we have proper pagination for wp_get_archives (see #30994), I think it would make sense to allow admins to customize the LIMIT clause in some scenarios.

Change History (10)

This ticket was mentioned in PR #10552 on WordPress/wordpress-develop by @jeherve.


3 weeks ago
#1

wp_get_archives already comes with 2 filters allowing one to customize some of the aspects of the queries to fetch archives on a site:

  • getarchives_where allows you to customize the WHERE clause
  • getarchives_join allows you to customize the JOIN clause

I think it would be useful to add a new filter, to allow customizing the LIMIT clause as well. In some environments, with sites with lots of posts with longform content, some of those queries can be really resource-intensive.

[!NOTE]
I have 2 notes about my PR:

  1. I used 7.0.0 as the since value. I'm not sure if I'm supposed to use a placeholder until this is ready for commit.
  2. I used the same filter prefix as the other filters in the function, even though they do not follow the typical wp_ prefix of other, newer filters. Let me know if I should change that.

*

#2 @westonruter
3 weeks ago

  • Milestone changed from Awaiting Review to 7.0
  • Owner set to westonruter
  • Status changed from new to reviewing

#3 @westonruter
3 weeks ago

  • Keywords changes-requested added

#4 @jeherve
2 weeks ago

  • Keywords changes-requested removed

@westonruter commented on PR #10552:


2 weeks ago
#5

Something that just came to mind: instead of introducing a filer specifically for the limit arg, what if there was a getarchives_args filter instead which filters the $parsed_args? This would be similar to other such filters like:

@jeherve commented on PR #10552:


2 weeks ago
#6

instead of introducing a filer specifically for the limit arg, what if there was a getarchives_args filter instead which filters the $parsed_args?

This would work ; I suppose it would then not be consistent with the existing filters for the archives though.

@westonruter commented on PR #10552:


2 weeks ago
#7

I think that's OK. The other filters are explicitly lower-level for manipulating the SQL, whereas this limit filter is really just a subset of filtering all of the parsed args.

@jeherve commented on PR #10552:


2 weeks ago
#8

I just pushed a new commit to try that.

@jeherve commented on PR #10552:


2 weeks ago
#9

Any thoughts about placement of the filter before or after the $parsed_args are collected?

I thought about it too, and figured it may be nice to have the filtering happen before, so we still come out with a consistently formatted $parsed_args.

#10 @westonruter
13 days ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 61326:

General: Add wp_get_archives_args filter to wp_get_archives().

Developed in https://github.com/WordPress/wordpress-develop/pull/10552

Props jeherve, westonruter.
Fixes #64304.

Note: See TracTickets for help on using tickets.