Is 136 the post ID? Also, you placed the wpp_get_views function inside the loop, right?
Thread Starter
hklim
(@hklim)
Yeap, 136 is the post ID. And I even put it directly under the loop.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<?php wpp_get_views(136); ?>
I did a little debugging with it’s function.
function wpp_get_views($id = NULL) {
// have we got an id?
if ( empty($id) || is_null($id) || !is_numeric($id) ) {
echo "alert!";
return false;
} else {
global $wpdb;
$table_name = $wpdb->prefix . "popularpostsdata";
$result = $wpdb->get_results("SELECT pageviews AS 'views' FROM $table_name WHERE postid = '$id'", ARRAY_A);
if ( !is_array($result) || empty($result) ) {
return "0";
} else {
return $result[0]['views'];
}
}
}
It seems like it’s not getting and ID.
Hi hklim,
I was kinda tired when I first replied to your thread. You need to echo it, like this:
This post has been viewed <?php echo wpp_get_views(the_ID()); ?> times so far.
That should work.
I’ve already corrected the documentation to include this info. Thanks for your feedback!
Thread Starter
hklim
(@hklim)
Yes, that’s working now. Thank you very much 🙂