[wp-trac] [WordPress Trac] #24597: get_{$adjacent}_post_sort filter should have post type parameter
WordPress Trac
noreply at wordpress.org
Wed Jun 19 00:17:38 UTC 2013
#24597: get_{$adjacent}_post_sort filter should have post type parameter
----------------------------+------------------------------
Reporter: helgatheviking | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: |
----------------------------+------------------------------
Comment (by knutsp):
Replying to [ticket:24597 helgatheviking]:
> The post type is already a variable is already passed in the preceding
post_where filter.
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 in
`apply_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:
{{{
function knutsp_previous_post_sort( $sort ) {
if ( 'foo' === get_post_type() )
return "ORDER BY p.post_title DESC LIMIT 1";
else
return $sort;
}
add_filter( 'get_previous_post_sort', 'knutsp_previous_post_sort' );
}}}
or like this:
{{{
function knutsp_previous_post_where( $where ) {
global $wpdb, $post;
if ( 'foo' === $post->post_type )
return $wpdb->prepare( "WHERE p.post_title < '%s' AND
p.post_type = 'foo' AND p.post_status = 'publish'", $post->post_title );
else
return $where;
}
add_filter( 'get_previous_post_where', 'knutsp_previous_post_where' );
}}}
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`and
`get_{$adjacent}_post_join`).
I really can't see the need for this extra parameter.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/24597#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list