Why is my function timing out?
When the issue was first noticed I added wp_defer_term_counting('true') to delay that process but to no avail.
/* Filter category from get_categories and wp_list_categories */
add_filter('list_terms_exclusions', 'my_list_terms_exclusions', 10, 2);
function my_list_terms_exclusions($exclusions, $args) {
global $my_sc_id;
// Defer term counting as its a heavy operation and may time out the server
wp_defer_term_counting('true');
if (!is_admin() && $my_sc_id) {
//Get the secret category and all its descendents
$list_terms_exclusions = my_sc_return_secret_cats($elbone_sc_id); // Returns an array
// Implode array
$list_terms_exclusions_string = implode(',', $list_terms_exclusions); // Returns a string
// Filter
$list_terms_exclusions_clean = wp_parse_id_list($list_terms_exclusions_string);
// Add to SQL query
foreach ($list_terms_exclusions_clean as $ex) {
if (empty($exclusions))
$exclusions = ' AND ( t.term_id <> '.intval($ex).' ';
else
$exclusions .= ' AND t.term_id <> '.intval($ex).' ';
}
// Closing bracket
if (!empty($exclusions))
$exclusions .= ')';
// Modify query
return $exclusions;
}
// Enable term counting
wp_update_term_count();
}
EDIT: The contents of the elbone_sc_return_secret_cats function.
/* Return child categories as array */
function elbone_sc_return_secret_cats($elbone_sc_id) {
// Add the child cats to the array
$sc_children = get_terms('category', 'child_of='.$elbone_sc_id);
foreach ($sc_children as $sc_child) {
$sc_child_ids[] = $sc_child->term_id;
}
// Add the parent category
$sc_child_ids[] = $elbone_sc_id;
// Return results
return (array)$sc_child_ids;
}
PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 48 bytes) in /XXX/wp-includes/functions.php on line 3172andPHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 261900 bytes) in /XXX/wp-includes/plugin.php on line 2650– Niels Feb 14 '12 at 2:12wp_parse_argsand the second to a line that does not exist :-( Nothing in SQL logs – Niels Feb 14 '12 at 2:14