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:

<?php
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>';

Comments

    Author’s gravatar

    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.
    ‘; ?>

    Author’s gravatar

    Hi, thank you for commenting, please keep in mind, this code should be added in your theme directory, not in the setting page.

Comments are closed.

Let’s get started
Take your business to next level

Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.