Make WordPress Core

Opened 3 years ago

Last modified 7 weeks ago

#35761 reopened enhancement

Add filter(s) to get_adjacent_post function to change variables further down

Reported by: briandichiara Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-patch, bulk-reopened
Focuses: Cc:


I'm finding it incredibly difficult to sort a post type using the existing filters to order by custom post meta alphabetically on a single post (for next/previous post).

A use case is when I have a separate field for a custom post type called "Last Name" where I would want my posts to display in alphabetical order by last name. When sorting on an archive with pre_get_posts, it's not a problem, however when navigating posts from the single post, there just doesn't appear to be a simple way to change the "next" and "previous" posts to maintain the same custom sort order when dealing with an alphabetical meta_value.

I'm proposing adding one or two filters to the get_adjacent_post() function which allows the final query to be filtered, or more importantly, the query result to be filtered so a custom sort can be implemented.

Attachments (1)

get_adjacent_post_filters.patch (1.4 KB) - added by briandichiara 3 years ago.
patch to link-template.php to add 2 new filters

Download all attachments as: .zip

Change History (5)

3 years ago

patch to link-template.php to add 2 new filters

#1 @swissspidy
3 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

Hey Brian

The use case sounds reasonable. Two notes on the patch:

  1. The filters need appropriate documentation, see for more information
  2. Since $join, $where and $sort are used in the query string, these variables should probably passed to the filter callback as well.

#2 @chriscct7
3 years ago

  • Version trunk deleted

#3 @iseulde
3 months ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This ticket has not seen any activity in over *two* years, so I'm closing it as "wontfix".

The ticket may lack decisiveness, may have become irrelevant, or may not have gathered enough interest.

If you think this ticket does deserve some attention again, feel free to reopen.

For bugs, it would be great if you could provide updated steps to reproduce against the latest version of WordPress (5.0.2 at the time of writing). Remember images or a video can be superior to explain a problem. At the very least, quickly test again to make sure the bug still exists.

If it’s an enhancement or feature, some extra motivation may help.

Thank you for your contributions to WordPress! <3

#4 @JeffPaul
7 weeks ago

  • Keywords bulk-reopened added
  • Milestone set to Awaiting Review
  • Resolution wontfix deleted
  • Status changed from closed to reopened

A decision was made to reopen tickets that were closed in the bulk edit that this ticket was affected by. This ticket is being placed back into the Awaiting Review milestone so it can be individually evaluated and verified to determine if it is still relevant/valid or reproducible.

Note: See TracTickets for help on using tickets.