Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;

}
share|improve this question

closed as too localized by toscho Dec 26 '12 at 22:52

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
any errors in the log? –  rexposadas Feb 13 '12 at 21:35
    
PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 48 bytes) in /XXX/wp-includes/functions.php on line 3172 and PHP 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:12
    
The first refers to wp_parse_args and the second to a line that does not exist :-( Nothing in SQL logs –  Niels Feb 14 '12 at 2:14
    
the only thing i can think of is if my_sc_return_secret_cats() is the culprit. i don't see anything weird that sticks out from the code you posted. –  rexposadas Feb 14 '12 at 17:55
    
That's a function I have been using throughout my plugin without any ill effects. It's pretty basic really. I will add it to my question. –  Niels Feb 14 '12 at 22:59