WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 22 months ago

#35761 new enhancement

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

Reported by: briandichiara Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Query Keywords: needs-patch
Focuses: Cc:

Description

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 2 years ago.
patch to link-template.php to add 2 new filters

Download all attachments as: .zip

Change History (3)

@briandichiara
2 years ago

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

#1 @swissspidy
2 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
22 months ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.