Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#16703 closed defect (bug) (fixed)

Post permalinks that include %category% should not query the category

Reported by: ryan's profile ryan Owned by:
Milestone: 3.1.1 Priority: normal
Severity: normal Version: 3.1
Component: Query Keywords: has-patch needs-testing needs-moar-testing
Focuses: Cc:

Description

3.1 now includes the category in the query when resolving a post permalink that includes %category%. 3.0 did not do this. This results in 'cat' and other category query vars being set for single post queries. This confuses some plugins and unnecessarily complicates the query. %category% is purely decorative since the post name is sufficient to find a post.

Discovered here:

http://wordpress.org/support/topic/plugin-the-events-calendar-compatibility-with-wordpress-31?replies=11#post-1971053

Attachments (1)

16703.diff (725 bytes) - added by scribu 14 years ago.
check is_singular before altering query

Download all attachments as: .zip

Change History (12)

#1 @ryan
14 years ago

3.0 query when resolving /%category%/%postname%/:

SELECT wp_30_posts.* FROM wp_30_posts WHERE 1=1 AND wp_30_posts.post_name = 'an-event' AND wp_30_posts.post_type = 'post' ORDER BY wp_30_posts.post_date DESC 

3.1 query:

SELECT wp_trunk_posts.* FROM wp_trunk_posts INNER JOIN wp_trunk_term_relationships ON (wp_trunk_posts.ID = wp_trunk_term_relationships.object_id) WHERE 1=1 AND wp_trunk_posts.post_name = 'an-event' AND ( wp_trunk_term_relationships.term_taxonomy_id IN (3) ) AND wp_trunk_posts.post_type = 'post' GROUP BY wp_trunk_posts.ID ORDER BY wp_trunk_posts.post_date DESC 

#2 @ryan
14 years ago

Note that is_category is being correctly set to false. Many plugins seem to be assuming a category query if 'cat' is set, however. One could argue that setting 'cat' is correct, but let's preserve the old expectation as well as get rid of the term query gymnastics for single post queries.

#3 @scribu
14 years ago

  • Version set to 3.1

#4 @scribu
14 years ago

The SQL is indeed altered, but 'cat' isn't set, at least not in my testing.

@scribu
14 years ago

check is_singular before altering query

#5 @scribu
14 years ago

  • Keywords has-patch needs-testing needs-moar-testing added

#6 @ryan
14 years ago

No problems so far in testing. Single post queries with various permalinks look good. Category queries look good. Seems to fix The Events Calendar.

#7 @ryan
14 years ago

3.1 query with the patch:

SELECT wp_trunk_posts.* FROM wp_trunk_posts WHERE 1=1 AND wp_trunk_posts.post_name = 'an-event' AND wp_trunk_posts.post_type = 'post' ORDER BY wp_trunk_posts.post_date DESC 

#8 @hakre
14 years ago

Related: #16465

#9 @ryan
14 years ago

[17504] for trunk

#10 @ryan
14 years ago

[17505] for 3.1.

#11 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.