Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hsleonis/0b8540920f0c750c4b2a3d80fdc80fe7 to your computer and use it in GitHub Desktop.
Save hsleonis/0b8540920f0c750c4b2a3d80fdc80fe7 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 <[email protected]>
* 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",
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment