[wp-trac] [WordPress Trac] #17807: get_adjacent_post() doesn't work with custom taxonomies

WordPress Trac wp-trac at lists.automattic.com
Wed Jun 15 09:51:47 UTC 2011


#17807: get_adjacent_post() doesn't work with custom taxonomies
--------------------------+-----------------------------
 Reporter:  avaly         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Taxonomy      |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 If you use `next_post_link('%link', '%title', true)` or
 `previous_post_link('%link', '%title', true)` to get the adjacent post for
 a custom post type which has a taxonomy assigned to it, it doesn't work as
 intended.

 The bug traces back to `get_adjacent_post()`. If the $in_same_cat
 parameter is true, then the SQL query built to get the posts are hardcoded
 using the default 'category' taxonomy. Instead it should allow a custom
 taxonomy as a parameter and use it in the queries.

 Example:

 Custom Post Type: `product`

 Custom Taxonomy: `color`

 SQL produced by `get_adjacent_post()` when calling
 `next_post_link('%link', '%title', true)`:

 `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 > '2011-06-14 19:37:08' AND p.post_type = 'product' AND
 p.post_status = 'publish' AND tt.taxonomy = 'category' ORDER BY
 p.post_date ASC LIMIT 1`

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17807>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list