WordPress dashboard, viewing CPT results in 504

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() ) {
         return;
     }
     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. **

Leave a Comment