How to get a Page Stats list by the slug

You can make a list from Page Stats, including ID, Count, and Page Slug, by the following code:

global $wpdb, $table_prefix;
$page_slug = '%about%';
$pages     = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$table_prefix}statistics_pages` WHERE `uri` LIKE %s", $page_slug ) );

echo '<table border="1"><tr><td>ID</td><td>Count</td><td>Slug</td></tr>';
foreach ( $pages as $page ) {
	echo "<tr><td>{$page->id}</td><td>{$page->count}</td><td>{$page->uri}</td></tr>";
echo '</table>';


  1. I tried putting that code in the “Notification” “Message body” field.

    This is what I have in the Message body:

    This was automatically created and sent.

    Page views for “In the News”: [wpstatistics stat=page time=week id=in-the-news]
    Page views for “Home”: [wpstatistics stat=page time=week id=home]
    Yesterday’s Visitors: [wpstatistics stat=visitors time=yesterday]
    Yesterday’s Visits: [wpstatistics stat=visits time=yesterday]
    Last Week’s Visitors: [wpstatistics stat=visitors time=week]
    Last Week’s Visits: [wpstatistics stat=visits time=week]
    Total Visitors: [wpstatistics stat=visitors time=total]
    Total Visits: [wpstatistics stat=visits time=total]

    get_results( $wpdb->prepare( "SELECT * FROM `{$table_prefix}statistics_pages` WHERE `uri` LIKE %s", $page_slug ) );

    echo 'IDCountSlug';
    foreach ( $pages as $page ) {
    echo "{$page->id}{$page->count}{$page->uri}";
    echo '';

    I get the following in the email.

    get_results( $wpdb->prepare( “SELECT * FROM `{$table_prefix}statistics_pages` WHERE `uri` LIKE %s”, $page_slug ) ); echo ‘
    ID Count Slug
    ‘; foreach ( $pages as $page ) { echo ”
    {$page->id} {$page->count} {$page->uri}
    “; } echo ‘ {{{there’s a message up table here }}} which also has some of the PHP in it.
    ‘; ?>

Leave Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.