Create a gist now

Instantly share code, notes, and snippets.

Speed up the post list views in WordPress admin UI screens. Reduce the queried fields to what is needed to display the posts and what "Quick Edit" needs. Saved time increases with a higher limit set for `posts_per_screen` in the screen options drop down.
<?php
defined( 'ABSPATH' ) OR exit;
/**
* Plugin Name: (WCM) Faster Admin Post Lists
* Description: Reduces the queried fields inside WP_Query for WP_Post_List_Table screens
* Author: Franz Josef Kaiser <wecodemore@gmail.com>
* AuthorURL: http://unserkaiser.com
* License: MIT
*/
add_filter( 'posts_fields', 'wcm_limit_post_fields_cb', 0, 2 );
function wcm_limit_post_fields_cb( $fields, $query )
{
if (
! is_admin()
OR ! $query->is_main_query()
OR ( defined( 'DOING_AJAX' ) AND DOING_AJAX )
OR ( defined( 'DOING_CRON' ) AND DOING_CRON )
)
return $fields;
$p = $GLOBALS['wpdb']->posts;
return implode( ",", array(
"{$p}.ID",
"{$p}.post_title",
"{$p}.post_date",
"{$p}.post_author",
"{$p}.post_name",
"{$p}.comment_status",
"{$p}.ping_status",
"{$p}.post_password",
) );
}
@prasenjithaty

Does this not work with custom post types?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment