Cada vez que llamo a WP_Query () en la función a continuación, Wordpress pierde 8 megas de memoria. Y como llamo mucho a esta función, las cosas se ponen complicadas bastante rápido ... :( He intentado desarmar el $ queryObject resultante, así como llamar periódicamente a wp_cache_flush (), pero ninguno parece tener ningún efecto. ¿Alguna idea?
function get_post_ids_in_taxonomies($taxonomies, &$terms=array()) {
    $post_ids = array();
    $query = gen_query_get_posts_in_taxonomies($taxonomies, $terms);
    // var_dump($query);
    //Perform the query
    $queryObject = new WP_Query($query); //*****THE 8 MEGABYTES IS LEAKED HERE*****
    //For all posts found...
    if($queryObject->have_posts()) {
        while($queryObject->have_posts()) {
            $queryObject->the_post();
            //Get the $post_id by capturing the output of the_ID()
            ob_start();
            the_ID();
            $post_id = (int) ob_get_contents();
            ob_end_clean();
            // echo $post_id."\n";
            $post_ids[] = $post_id;
        }
    }
    unset($queryObject);
    return $post_ids;
}
gen_query_get_posts_in_taxonomies () es:
function gen_query_get_posts_in_taxonomies($taxonomies, &$terms=array()) {
    //General query params
    $query = array(
        'posts_per_page'    => -1,  //Get all posts (no paging)
        'tax_query'             => array('relation' => 'OR'),
    );
    //Add the specific taxonomies and terms onto $query['tax_query']
    foreach($taxonomies as $tax) {
        //Get terms in the taxonomies if we haven't yet
        if(!array_key_exists($tax, $terms)) {
            $terms[$tax] = array();
            $terms_tmp = get_terms($tax);
            foreach($terms_tmp as $tt)
                $terms[$tax][] = $tt->term_taxonomy_id;
        }
        $query['tax_query'][] = array(
            'taxonomy' => $tax,
            'terms' => $terms[$tax],
            'field' => 'term_taxonomy_id',
        );
    }
    return $query;
}

WP_Querysi su caso (cuando se filtran 8mb)?Respuestas:
Excelentes respuestas en WP Hackers: http://lists.automattic.com/pipermail/wp-hackers/2012-June/043213.html
fuente
Tropecé con esto mientras investigaba el problema de memoria señalado aquí.
En este caso, puede usar get_the_id en lugar de usar el almacenamiento en búfer para capturar la identificación, y puede limitar los campos consultados para incluir solo identificadores.
fuente