Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#35761 new enhancement

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

Reported by: briandichiara's profile briandichiara Owned by:
Milestone: 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 (2)

get_adjacent_post_filters.patch (1.4 KB) - added by briandichiara 9 years ago.
patch to link-template.php to add 2 new filters
35761.patch (995 bytes) - added by ramiy 4 years ago.

Download all attachments as: .zip

Change History (4)

@briandichiara
9 years ago

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

#1 @swissspidy
9 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
8 years ago

  • Version trunk deleted

@ramiy
4 years ago

Note: See TracTickets for help on using tickets.