2

I've set up three custom taxonomies within my theme for attachment post types within Wordpress 3.5.1. One taxonomy is non-hierarchical (i.e. tags) and has about 800 terms in it. (I'm using WP to build a quick & dirty stock photo site, and these taxonomy terms are akin to photo keywords. Yes, one could debate whether WP is the right tool for this...). Another of the taxonomies is flat as well and as yet has no terms in it.

In short, my site has become extremely slow. I'm not at all well-versed in MySQL or databases in general, but when I use the Blackbox plugin to get some insight into the underlying queries when pages load, I see that two queries in particular are adding huge overhead to my pages. Page request times are taking several seconds, and this wasn't happening prior to the creation of the taxonomies. One query alone (below) is taking on average 1.4 seconds.

What's going on, and is there a way to stop this? Is there a reason WP needs to make these expensive taxonomy queries on every single page?

Currently one query that WP is executing looks like:

SELECT t.*, tt.*, tr.object_id
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy IN ('myCustomTaxonomyName') AND tr.object_id IN (
    list of 200+ post IDs
)
ORDER BY t.name ASC;

And the other looks similar, except with different taxonomy names:

SELECT t.*, tt.*, tr.object_id
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id
INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy IN ('attachment_tax1', 'attachment_tax2') AND tr.object_id IN (
    list of 200+ post IDs
)
 ORDER BY t.name ASC;
7
  • 1
    what wp functions in your theme are generating these queries?
    – birgire
    Commented Feb 13, 2013 at 18:09
  • Your best bet it to turn off plugins and revert to the default theme, check is this still occurs.
    – Wyck
    Commented Feb 13, 2013 at 18:41
  • 1
    are you displaying 200+ posts per page?
    – birgire
    Commented Feb 13, 2013 at 18:43
  • Really I need to pay more attention. The default image.php template in the WP 'twentytwelve' theme was looping through every single post in the DB to build an array of image attachments. I was using this template for testing purposes. Now that I've amended the way image.php fetches the (single) attached image, this doesn't occur.
    – Tim
    Commented Feb 13, 2013 at 18:45
  • ok great that the source of the problem is found ;-)
    – birgire
    Commented Feb 13, 2013 at 18:51

2 Answers 2

1

This has nothing to do with custom taxonomies. I was using a snippet of code from the default 'twentytwelve' theme for image.php that was looping through every single post in the blog to get child attachments, and thus the taxonomy associations for each of those posts. Amending my image.php by removing this foreach() loop fixed the issue.

-3

My experiences with slow WordPress websites, due to changes, are related to the PHP memory space. This is often a easy fix in the wp-config.php file. Add the following line at the end and you should see a change.

    define('WP_MEMORY_LIMIT', '64M');
1
  • Thanks for the tip, but unfortunately that hasn't solved the issue- these queries are still taking 1.5 seconds on average.
    – Tim
    Commented Feb 13, 2013 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.