Currently I am making a custom design for a site. The problem I'm seeing in Wordpress is about almost all data pulled out from the database.
While in certain pages - like front-page.php - it only needs, for example, title, category, two metas and the excerpt, WP gets everything. Hell, the post content is only visible in post-single.php, but instead WP pulls out all the content, tags, guid, tags, etc. where it can (print_r helps a lot).
The question is about how to limit Wordpress data pulled out from his queries. I think that I should make a net "WP_Query" (or override it) based on $wpdb and use it for the site, instead of using the default one. Well, at least functions like query_posts, WP_Query and get_posts doesn't allow me to limit the data pulled out.
I am also interested in caching the data, because is really small, but this is first.
Update 1: Tried to "minimize data":
add_action( 'pre_get_posts', 'disable_main_query' );
function disable_main_query( $query ) {
if( $query->is_main_query() && $query->is_front_page() ) {
add_filter('posts_fields', 'minimized_data');
}
}
function minimized_data($fields) {
global $wpdb;
$fields = "
$wpdb->posts.ID,
$wpdb->posts.post_title,
$wpdb->posts.post_excerpt,
$wpdb->posts.comment_count,
$wpdb->posts.guid,
$wpdb->posts.post_status,
$wpdb->posts.post_name,
$wpdb->posts.post_date,
$wpdb->posts.post_type
";
return $fields;
}
Mow the default loop is plagued with "Undefined property: stdClass::$post_XXXX" and other things. I think the_post is to blame now, so I'm cheking.
Update 2: Has expected, it was. Changed the while
loop for foreach ($posts as $post)
no more undefined properties, but as earlier I can't get rid of ob_end_flush() [ref.outcontrol]: failed to delete buffer zlib output compression
.
Update 3: define( 'SAVEQUERIES', FALSE );
and no more failed buffer (for WAMP).