[wp-trac] [WordPress Trac] #26937: get_adjacent_post() should use WP_Query rather than build its own SQL query

WordPress Trac noreply at wordpress.org
Tue Mar 11 19:31:42 UTC 2014


#26937: get_adjacent_post() should use WP_Query rather than build its own SQL query
-------------------------+-----------------------
 Reporter:  ethitter     |       Owner:  nacin
     Type:  enhancement  |      Status:  reopened
 Priority:  normal       |   Milestone:  3.9
Component:  Query        |     Version:  3.7
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+-----------------------
Changes (by kovshenin):

 * status:  closed => reopened
 * resolution:  fixed =>


Comment:

 Noticing some breakage here with themes and plugins.

 While the get_*_post_* filters seem to be backwards compatible, they're a
 little different than what some plugins expect: the whole WHERE statement
 is filtered pre r27285, so plugins that write their own WHERE statements
 (as opposed to appending conditions to the clause) will end up with an
 invalid SQL.

 Also, the former SQL statement declared a `p` alias for `$wpdb->posts`,
 but WP_Query doesn't do that, so any references to fields in where and
 join filters are broken.

 Here's some sample code that illustrates both problems:

 {{{
 add_filter( 'get_previous_post_where', function( $where ) {
         global $wpdb;
         $post = get_post();
         $where = $wpdb->prepare( " WHERE p.post_date < %s AND p.post_type
 IN ( 'post', 'page' ) ", $post->post_date );
         return $where;
 });
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26937#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list