I created a custom post type with a custom taxonomy. I have about 1500 posts all of which are assigned to some sort of taxonomy term...some being assigned to 200+ terms.

I noticed that from the dashboard, it takes an extremely long amount of time to view the custom post types, most of the time resulting in a 504 Gateway Time-Out.

Querying these post from the front-end is just fine and I have no issues with that.

It's my understanding that when the dashboard is trying to view these custom post types, it's trying to pull all the information assigned to each post, before it shows everything.

I do have this WP install set to be able to use as much memory as needed (memory_limit = -1), as I was researching, some said it may be memory related.

Is there something i can do to increase the performance of this query ...maybe not load all the taxonomy term relationships of a post until you're editing the post?

Errors after increasing WP_MEMORY_LIMIT from 1Gb to 2Gb:

WordPress database error: [MySQL client ran out of memory]
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 ('locations') AND tr.object_id IN

WordPress database error: [Lost connection to MySQL server during query]
SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN

WordPress database error: [MySQL server has gone away]
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM wp_posts WHERE post_type = 'services' ORDER BY post_date DESC
  • FWIW, I did increase the memory of my WordPress site to 2Gb and that allowed me to see the posts, however I'm getting a slew of errors (added to original question). Is there anything that can be done to make the query on the back-end not so heavy?
    – NW Tech
    Apr 22, 2013 at 17:12
  • When you mention viewing the custom post types from the dashboard, are you referring to viewing the list of posts located at wp-admin/edit.php?post_type=services?
    – bosco
    Apr 25, 2013 at 21:57
  • @bosco That is correct.
    – NW Tech
    Apr 26, 2013 at 1:19
  • That is an awful lot of memory to be assigning to Wordpress. Are you on shared hosting, a VPS or dedicated server? There could be deeper underlying issues here. Are you using Apache or another webserver like Nginx (perhaps both)? Apr 26, 2013 at 2:13
  • This is a new server (dv) with MediaTemple. The control panel is Plesk and the server is running CentOS with Apache and Nginx. I don't want to be assigning this much memory, but it seemed like the only way to get any results.
    – NW Tech
    Apr 26, 2013 at 2:53

1 Answer 1


The CPT and taxonomy terms are created via plugin. I was able to lessen the query by adding the following to my plugin:

add_action( 'pre_get_posts', 'nwtd_lpfs_custom_admin_query' );
function nwtd_lpfs_custom_admin_query( $query ) {
    if( !is_admin() && !$query->is_main_query() ) {
     if( is_post_type_archive( 'services' ) ) {
          $query->set('no_found_rows', 1 );
          $query->set('update_post_meta_cache', 0 );
          $query->set('update_post_term_cache', 0 );

As of currently, I have 700+ posts tied to 1500+ taxonomy terms and everything is working great. The posts are showing up almost instantaneously.

** I did not write this code. Someone I work with directly, who is not part of the WordPress Answers community, provided the code -- maybe it can help someone else, or someone else can possibly expand off it to make it more efficient. **


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.