Background issue: https://toolset.com/forums/topic/wp-admin-edit-screen-super-slow/
Hi,
I am using toolset for a WordPress site with a very large database. When I go to Edit a Post Field Group and click on Where to include this Field Group, toolset is timing our and throwing an error.
My error log shows that my hosting provider is killing the query because its excessively large and hogging too much memory.
KILLED QUERY (30816 characters long generated in /wp-content/plugins/types/vendor/toolset/types/includes/classes/class.types.admin.edit.custom.fields.group.php:845): SELECT term_id, meta_key, meta_value FROM wp_termmeta WHERE term_id IN (55750,55662,55836,56051, ect....)
And I am getting a 500 error.
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20074496 bytes) in /wp-content/plugins/types/vendor/toolset/types/includes/classes/class.types.admin.edit.fields.php on line 1447
My wp_terms table has 45768 rows. The wp_termmeta table has 305984 rows.
I took a look at line 845 in class.types.admin.edit.custom.fields.group.php It's calling the WordPress function 'get_terms'
$terms = apply_filters( 'wpcf_group_form_filter_terms', get_terms( $category_slug, array('hide_empty' => false) ) );
Your function 'form_add_filter_dialog' looks like its building the form of checkboxes for the edit page so a user can select which post-types, taxonomies, and templates will be available to apply the post field group to.
# class.types.admin.edit.custom.fields.group.php
# start line 777
protected function form_add_filter_dialog( $filter, &$form ) {
global $wpcf;
switch( $filter ) {
/**
* post types
*/
case 'post-types':
// ...
/**
* taxonomies
*/
case 'taxonomies':
// ...
/**
* templates
*/
case 'templates':
// ...
}
}
My question is, why when building the admin edit form does the code need to deeply dive into each term of each taxonomy? In cases like mine, where we have a large number of terms and termmeta, this is causing my memory to run out. Even if I had more memory from my server, its not necessary to call on every single term when assigning post fields to a post type. It seems like here we are dealing with postmeta and post types, but don't need to look at terms of taxonomies. I only have 15 taxonomies registered.
For better performance, I think you all should rethink the case statement for taxonomies, and get by with looking at each taxonomy and not dive into each term.
Thanks,
Harry
PS. I solved my problem I was having with my background issue linked above. When I was visiting the admin edit screen for my custom post type, the edit screen was displaying the meta boxes for the attached taxonomies. The taxonomies were setup as Hierarchical causing a dropdown list to be created. And in displaying the taxonomy dropdown, every singe term of the taxonomy was being listed as a choice. Way too many! I changed my taxonomy settings to be structured as Flat instead of hierarchical and this fixed the problem. On the custom post type admin edit screen, instead of a dropdown being shown, there now is a free-form entry box which makes the page lightning fast since it does not have to query every single term.