Fixed problems with permalinks and stattraq/mostwanted

For a while now I have had the stattraq and mostwanted plugins installed. The idea is that stattraq logs statistics of how many users are visiting, which pages are popular etc. into a database. Then mostwanted picks out the most popular posts and lists them in the sidebar on the left.

Up until now I have only got the text "no results available" from mostwanted due to a problem with handling permalinks in stattraq. But today with some help from nice people on the #wordpress IRC channel I got it fixed. There are two things that need to be done.

Note: this fix is likely to work with only the permalink structure used here i.e. /Year/Mont/Day/PostTitle

First, in /wp-content/plugins/stattraq.php , right after the lines

$article_id = 0; // default/mixed page - not just for one article

insert this (thanks to Michelle Li for coming up with the fix)


$myName = $_GET['name'];
$myMon = intval($_GET['monthnum']);
$myYear = $_GET['year'];
$myDay = $_GET['day'];
$mysqlQuery = "SELECT ID as pid, UNIX_TIMESTAMP(post_date) as pdate FROM wp_posts WHERE post_name='$myName'";
$myOutput = $wpdb->get_results($mysqlQuery);
if (isset($myOutput)) {
foreach ($myOutput as $myline) {
$sDate = getdate($myline->pdate);
$myMon2 = $sDate['mon'];
$myYear2 = $sDate['year'];
$myDay2 = $sDate['mday'];
if($myMon==$myMon2 && $myYear==$myYear2 && $myDay==$myDay2) {
$article_id = $myline->pid;
}
}
}

Second, to fix all the hits that have accumulated wrongly in the database, there is a function fixstats() that can be run.

I did it simply by editing my sidebar template to include

< ?php MostWanted::fixstats(); ?>

and then loaded the homepage of my site once. Then you can remove the above line from the template.

Hope this helps someone with the same problem !

Now there should be an accurate popular posts list down in the sidebar on the left.

2 thoughts on “Fixed problems with permalinks and stattraq/mostwanted”

  1. Hi Rich,

    Your plugin has been working fine until recently. However for some time now Stattraq has not been recording visits to individual pages, all I get is a lot of hits to Multiple Posts. any ideas ?

    Anders

Comments are closed.