[wp-hackers] get_userdata and _fill_user causing huge number of database queries

Simon B piemanek at gmail.com
Wed Mar 3 22:50:40 UTC 2010


I've set up a test page as follows:

        query_posts( array(
                        'category'       => 1,
                        'meta_key'       => 'alpha-name',
                        'posts_per_page' => -1,
                        'order'          => 'ASC',
                        'orderby'        => 'meta_value',
                        'post_status'    => 'publish'
                        ) );

        if ( have_posts() ) {
            while ( have_posts() ) {
                the_post();
            }
        }

        foreach ( $wpdb->queries as $query ) {
            echo "<p>";
            print_r( $query );
            echo "</p>";
        }



For every post returned, those two db queries (get_userdata and _fill_user)
are taking place. From the debug output it looks to me that it's the_post()
that is calling them:

Array ( [0] => SELECT * FROM xn3t_users WHERE ID = 11 LIMIT 1 [1] =>
0.00041818618774414 [2] => require, require_once, include, the_post,
WP_Query->the_post, setup_postdata, get_userdata )

Array ( [0] => SELECT meta_key, meta_value FROM xn3t_usermeta WHERE user_id
= 11 [1] => 0.0011389255523682 [2] => require, require_once, include,
the_post, WP_Query->the_post, setup_postdata, get_userdata, _fill_user )


More information about the wp-hackers mailing list