Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15322 closed defect (bug) (fixed)

Skip category and tag queries on non posts in get_post_class()

Reported by: mfields Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.1
Component: Template Keywords: dev-feedback has-patch
Focuses: Cc:


Where post_class() is used in a loop that iterates over an array of non-post objects get_post_class() will query for categories and tags regardless. Most times, these taxonomies are not registered with the post_type. This bug results in 2 additional queries per iteration. Please see attached (post-class-test.php) for an example using attachments.

Attachments (2)

post-class-test.php (1.8 KB) - added by mfields 4 years ago.
How to reproduce
15322.patch (1.1 KB) - added by mfields 4 years ago.

Download all attachments as: .zip

Change History (10)

@mfields4 years ago

How to reproduce

@mfields4 years ago

comment:1 @scribu4 years ago

  • Milestone changed from Awaiting Review to 3.1

comment:2 @scribu4 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [16204]) Skip category/tag queries if post type doesn't support them. Props mfields. Fixes #15322

comment:3 @mfields4 years ago

Scribu. No problem! Been trying to find ways to help out in here. What could I have been done better with the patch?

comment:4 @scribu4 years ago

Well, the patch was made relative to the wp-includes folder, when it should have been made relative to the wp folder.

Less importantly, if( should have been if ( as per the coding standards.

comment:5 @mfields4 years ago

I thought that might be the issue. I used Tortoise SVN to create the patch and there was not an option for anything like this. I have yet to use svn via the command line, but I can definitely learn.

Could you please explain how to do this?

I'll reread the coding standards.
I missed that bit before.

comment:6 @scribu4 years ago

Unfortunately, there's no command line version of svn for Windows.

And I'm on Ubuntu, so I don't know how you should do it via TortoiseSVN.

comment:7 @nacin4 years ago

mfields: Navigate to the site root, then right-click inside the directory (no file in particular), then create a patch from there. You'll get a diff relative to the root for all files modified.

comment:8 @mfields4 years ago

nacin: That's easy. Thanks! Will definitely do this next time.

Note: See TracTickets for help on using tickets.