Skip to content

Instantly share code, notes, and snippets.

@guillaumemolter
Created July 15, 2019 18:07
Show Gist options
  • Save guillaumemolter/31995e574f1b16b3abbc7549751409a7 to your computer and use it in GitHub Desktop.
Save guillaumemolter/31995e574f1b16b3abbc7549751409a7 to your computer and use it in GitHub Desktop.
WordPress multisite content freshness report
<?php
// To run it, place into web root and then `wp eval-file stats.php > ~/stats.csv`
global $wpdb;
$sites = $wpdb->get_results( "SELECT blog_id,domain,path,last_updated FROM {$wpdb->prefix}blogs",'ARRAY_A' );
foreach( $sites as &$site){
if($site['blog_id'] === '1'){
$post_table = $wpdb->prefix . 'posts';
} else {
$post_table = $wpdb->prefix . absint($site['blog_id']) . '_posts';
}
$site['posts_number'] = $wpdb->get_var( "SELECT count(*) FROM $post_table WHERE post_type NOT IN ('revision','nav_menu_item','custom_css','customize_changeset','oembed_cache','user_request','wp_block')" );
}
WP_CLI\Utils\format_items( 'csv', $sites, array( 'blog_id', 'domain','path','last_updated','posts_number' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment