The Debug Bar plugin has become one of my best friends lately. I’ve been spending a large portion of the last few months optimizing and rewriting a pretty large WP multisite. I’ve been scrutinizing queries and cache bashing like Mario on mushrooms. While looking through error logs today, I found something interesting, the site lost its connection to the MySQL server while doing a query involving the ‘post_format’ taxonomy. Now I don’t blame Post Formats for my DB issues, the two are unrelated and this was just a coincidence.
The thing is, I don’t have ‘post_format’ support registered in any of the themes I’m using. My false assumption was that if I don’t register theme support for something, then it doesn’t exist. Wrongish. I go to the admin panel for my dev environment and go to Posts->Add New, pop open Debug Bar and I see this:
Where is it coming from? Well, it comes from the create_initial_taxonomies() function in wp-includes/taxonomy.php
On init, the ‘post’ post type gets the post_format taxonomy. No matter what. If I wanted it, I’d ask for it.
Edit: Wait, there’s more! On the initial creation of post types, ‘post’ gets support for ‘post-formats’.
This means every time your theme calls ‘post_class()’, or ‘body_class()’ on single pages, we get more unneeded queries. Here’s the unneeded query that runs every time you use ‘post_class()’:
‘post_class()’ calls ‘get_post_class()’, which does a check for if ‘posts’ support ‘post-formats’, which it does by default. Then it calls ‘get_post_format()’:
Here’s a fun bit, ‘get_post_format()’ does a check for if the post type supports ‘post-formats’. WP just did that already!
You can use the following function will get rid of these unneeded queries on your site:
remove_post_type_support( 'post', 'post-formats' );
The concept is neat, but since you can’t add your own formats, I don’t use them. Nacin has a great post on post formats and in it says “If you want a custom post format, then chances are you shouldn’t be using post formats.” While I don’t like the idea of rebuilding what’s already been built, just to be able to customize or add to it, that’s the only option there is, and on that note, that’ll be the topic of my next post, Custom Post Formats, and I’ll be presenting on that topic at Internet Club NYC on May 27 if you’re in New York.