WordPress.org

Make WordPress Core

#22360 closed defect (bug) (duplicate)

Database Error with previous_post_link and next_post_link functions

Reported by: neonwired Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Template Keywords: has-patch commit
Focuses: Cc:

Description

Passing a value of 1 or true for the in_same_cat argument results in a database error.

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') WHERE p.post_date < '2012-10-14 17:16:13' AND p.post_type = 'project' AND p.po' at line 1]
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 < '2012-10-14 17:16:13' AND p.post_type = 'project' AND p.post_status = 'publish' AND tt.taxonomy = 'category' ORDER BY p.post_date DESC LIMIT 1

Attachments (1)

22360.patch (936 bytes) - added by SergeyBiryukov 18 months ago.

Download all attachments as: .zip

Change History (8)

comment:1 SergeyBiryukov18 months ago

  • Component changed from General to Template
  • Keywords reporter-feedback added

Could not reproduce neither in 3.4.2 with Twenty Eleven nor in 3.5-beta2 with Twenty Twelve.

My steps:

  1. Open single.php, add true to the previous_post_link() and next_post_link() calls:
    <?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ), true ); ?>
    <?php next_post_link( '%link', __( 'Next <span class="meta-nav">&rarr;</span>', 'twentyeleven' ), true ); ?>
    
  2. The post is displayed correctly, without a database error.

Could you provide some steps to reproduce the issue on a clean install?

comment:2 duck_18 months ago

The SQL is invalid due to missing term IDs in AND tt.term_id IN (). Not sure how this happened.

comment:3 neonwired18 months ago

This may only effect custom post types which obviously have custom taxonomies not categories. Will confirm if this is the case. No clues in the ref docs whether this is intended to work with custom post types.

Version 1, edited 18 months ago by neonwired (previous) (next) (diff)

comment:4 neonwired18 months ago

Tested it by adding a custom post type to the twenty eleven theme, no other edits, all plugins disabled still results in the same database error.

SergeyBiryukov18 months ago

comment:5 SergeyBiryukov18 months ago

  • Keywords has-patch added; reporter-feedback removed
  • Milestone changed from Awaiting Review to 3.5

Confirmed with a custom post type. $cat_array is empty in that case.

comment:6 nacin18 months ago

  • Keywords commit added

That appears good.

comment:7 nacin18 months ago

  • Milestone 3.5 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #15959.

Note: See TracTickets for help on using tickets.