[wp-trac] [WordPress Trac] #15959: get_adjacent_post() can generate invalid SQL
WordPress Trac
wp-trac at lists.automattic.com
Thu Dec 23 07:13:40 UTC 2010
#15959: get_adjacent_post() can generate invalid SQL
--------------------------+-----------------------------
Reporter: dd32 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.1
Severity: normal | Keywords:
--------------------------+-----------------------------
As reported on wp-testers, if get_adjacent_post() is used with
`$in_same_cat = true` on a post type which does not support categories,
then a invalid SQL will be generated.
eg:
{{{
SELECT p.* FROM wp_posts AS p INNER JOIN wp_term_relationships AS tr ON
p.ID = tr.object_id INNER JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id
= tt.term_taxonomy_id AND tt.taxonomy = 'category' AND tt.term_id IN ()
WHERE p.post_date < '2010-07-04 12:24:53' AND p.post_type = 'note' AND
p.post_status = 'publish' AND tt.taxonomy = 'category' ORDER BY
p.post_date DESC LIMIT 1
}}}
specifically
{{{
AND tt.term_id IN ()
}}}
Whilst this is not a problem in the 2011 theme, Some themes may call the
functions which can result in this.
wp-testers thread: http://lists.automattic.com/pipermail/wp-
testers/2010-December/013841.html
one potential solution would be:
{{{
// Check to see if the Post Type supports categories before
honoring the argument.
if ( $in_same_cat ) {
$taxonomies = get_object_taxonomies($post);
if ( ! in_array('category', $taxonomies) )
$in_same_cat = false;
}
}}}
From what I can see, this would not be a regression from any previous
version of WordPress
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15959>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list