WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 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:

Description

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 5 years ago.
How to reproduce
15322.patch (1.1 KB) - added by mfields 5 years ago.

Download all attachments as: .zip

Change History (10)

@mfields5 years ago

How to reproduce

@mfields5 years ago

comment:1 @scribu5 years ago

  • Milestone changed from Awaiting Review to 3.1

comment:2 @scribu5 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 @mfields5 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 @scribu5 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 @mfields5 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 @scribu5 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 @nacin5 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 @mfields5 years ago

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

Note: See TracTickets for help on using tickets.