Opened 10 years ago
Closed 8 years ago
#24597 closed enhancement (fixed)
get_{$adjacent}_post_sort filter should have post type parameter
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | has-patch needs-refresh |
Focuses: | Cc: |
Description
In case a user doesn't want to change the sort order for every post type, the post type should be passed as an extra parameter. The post type is already a variable is already passed in the preceding post_where filter.
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
should be updated with:
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post->post_type );
in wp-includes/link-template.php
Attachments (2)
Change History (10)
#1
in reply to:
↑ description
@
10 years ago
#2
@
10 years ago
My bad I guess. It looked like the post type was being passed. I appreciate the complete explanation... and would move to close this ticket.
#3
@
10 years ago
- Component changed from General to Post Types
- Resolution set to wontfix
- Status changed from new to closed
#4
@
10 years ago
- Resolution wontfix deleted
- Status changed from closed to reopened
In general it is best to not rely on global scope. Passing $post
to this filter makes a lot of sense. $post should probably be passed to all of these filters.
Note: See
TracTickets for help on using
tickets.
Replying to helgatheviking:
This is not quite correct. The post type is, as always, a property of the
$post
object, as$post->post_type
. This property is just passed as a parameter to the$wpdb->prepare()
method, which result is then passed inapply_filters()
call.I see no need for passing a property of a global object to a callback function, since the callback function, in this case may use
get_post_type()
, or, generally, use it directly by declaring the global object. Like I do in my child themes for sorting post type 'foo' by post title:or like this:
If this is needed for
get_{$adjacent}_post_sort
then it would be logical to also pass it for the other two filters (get_{$adjacent}_post_where
andget_{$adjacent}_post_join
).I really can't see the need for this extra parameter.