[wp-trac] [WordPress Trac] #4822: get_previous_post_join and
get_next_post_join cannot be used in certain cases
WordPress Trac
wp-trac at lists.automattic.com
Mon Aug 27 14:50:06 GMT 2007
#4822: get_previous_post_join and get_next_post_join cannot be used in certain
cases
---------------------+------------------------------------------------------
Reporter: Cimmo | Owner: anonymous
Type: defect | Status: new
Priority: normal | Milestone: 2.4 (next)
Component: General | Version:
Severity: normal | Keywords:
---------------------+------------------------------------------------------
get_previous_post_join and get_next_post_join cannot be used in some cases
because if someone add a INNER JOIN with another table that has the ID
column too then SQL return the error:
WordPress database error: [Column 'ID' in field list is ambiguous]
SELECT ID, post_title FROM wp_posts INNER JOIN wp_a51_posts AS a51_posts
ON wp_posts.ID=a51_posts.POST_ID WHERE post_date < '2007-07-12 12:31:13'
AND post_type = 'post' AND post_status = 'publish' AND a51_posts.LEVEL<=-1
ORDER BY post_date DESC LIMIT 1
I suggest to change these rows in get_previous_post function in link-
template.php:
line 325:
$join = " INNER JOIN $wpdb->post2cat ON p.ID= $wpdb->post2cat.post_id ";
line 346:
$where = apply_filters( 'get_previous_post_where', "WHERE p.post_date <
'$current_post_date' AND p.post_type = 'post' AND p.post_status =
'publish' $posts_in_ex_cats_sql", $in_same_cat, $excluded_categories );
line 347:
$sort = apply_filters( 'get_previous_post_sort', 'ORDER BY p.post_date
DESC LIMIT 1' );
line 349:
return @$wpdb->get_row("SELECT p.ID, p.post_title FROM $wpdb->posts AS p
$join $where $sort");
similar can be done into get_next_post function:
lines: 362, 383, 384, 386
--
Ticket URL: <http://trac.wordpress.org/ticket/4822>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list