Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save franz-josef-kaiser/5917688 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/5917688 to your computer and use it in GitHub Desktop.
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
Copy link

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