Make WordPress Core

Opened 13 years ago

Closed 13 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:


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:

Attachments (1)

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

Download all attachments as: .zip

Change History (12)

#1 @ryan
13 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
13 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
13 years ago

  • Version set to 3.1

#4 @scribu
13 years ago

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

13 years ago

check is_singular before altering query

#5 @scribu
13 years ago

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

#6 @ryan
13 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
13 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
13 years ago

Related: #16465

#9 @ryan
13 years ago

[17504] for trunk

#10 @ryan
13 years ago

[17505] for 3.1.

#11 @ryan
13 years ago

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