Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#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:


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 6 years ago.

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
6 years 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?

#2 @duck_
6 years ago

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

#3 @neonwired
6 years ago

This may only effect custom post type will confirm if this is the case.

Version 0, edited 6 years ago by neonwired (next)

#4 @neonwired
6 years 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.

#5 @SergeyBiryukov
6 years 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.

#6 @nacin
6 years ago

  • Keywords commit added

That appears good.

#7 @nacin
6 years 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.