All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.

Author Topic: Calling get_most_viewed() with Sniplets plugin...  (Read 8313 times)

0 Members and 1 Guest are viewing this topic.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Bolg: Wordpress 2.7.1
theme: Flexx by iThemes.com
url: http://thundercatownersgroup.com
Plugin: postviews 1.5
php: 5.2.9
mysql: v5.0.81-community

Possible Conflicting Plugin: Sniplets http://wordpress.org/extend/plugins/sniplets/
This plugin allows you to execute php in a post.

I have created a sniplet using this code:
<?php if (function_exists('get_most_viewed')); ?><ul><?php get_most_viewed(); ?></ul>

Whenever I use this sniplet in a post, it changes the displayed category assigned to the post, to the category of the last item in the list created by get_most_viewed().

Is there a way to prevent this like adding some additional code in the sniplet?


Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #1 on: 27 June 2009, 17:56 »
I think it is a problem with my WP-PostViews.

In line 214 of wp-postviews.php,

Find:
Code: [Select]
global $wpdb, $post;Replace:
Code: [Select]
global $wpdb;

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #2 on: 27 June 2009, 18:28 »
Thanks for quick reply and I LOVE your plugins. :D

This code changed fixed the category display problem but broke the listings portion. See screenshots.

Thanks,
Jeff

[attachment deleted by admin]

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #3 on: 27 June 2009, 18:50 »
Can you try the dev version - http://downloads.wordpress.org/plugin/wp-postviews.zip 10 minutes after the time of this post?

just overwrite wp-postviews.php and postviews-options.php

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #4 on: 27 June 2009, 18:58 »
Actually, I think I fixed it but not sure if what I did will break something else.
I kept your change mentioned earlier for line 218.

Here's my additional change on Line 235:

From this: $post_title = get_the_title();
To this: $post_title = get_the_title($post->ID);

Do you see a problem with this anywhere else like on the widgets or something?

[attachment deleted by admin]

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #5 on: 27 June 2009, 18:59 »
That fix is not efficient as it will generate 1 query per post, so if you have top 100 most viewed post it will generate 100 queries just for that function.

What I did was to replace it with get_the_title() to get_the_title($post); and get_permalink() to get_permalink($post); as seen http://plugins.trac.wordpress.org/changeset/130015

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #6 on: 27 June 2009, 19:02 »
Is that in the DEV version or should I just change the version I have now? If so, can you be more specific on which lines to change for the permalink?

Thanks,
Jeff

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #7 on: 27 June 2009, 19:04 »
Nevermind, i didn't read all of your last post. I'll check the changelog.
Jeff

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #8 on: 27 June 2009, 19:06 »
Yikes! That's a lot of changes and my line numbers are not matching. What do you recommend?

Is there a way to download just that file?

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #9 on: 27 June 2009, 19:10 »
Just download http://downloads.wordpress.org/plugin/wp-postviews.zip and overwrite the two files on your server, it will bump up the version to 1.60. It should fix it. It will work with WP2.8, I tested it.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #10 on: 27 June 2009, 19:11 »
OK thanks! I'll let you know.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #11 on: 27 June 2009, 19:15 »
Ouch!

Fatal error: Cannot redeclare widget_views_init() (previously declared in /home/jschodde/public_html/wp-content/plugins/wp-postviews/wp-postviews-widget.php:33) in /home/jschodde/public_html/wp-content/plugins/wp-postviews/wp-postviews.php on line 761

What should I do?

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #12 on: 27 June 2009, 19:16 »
Delete the whole folder /wp-postviews/, download the zip file from the url and extract /wp-postviews/ folder and upload. Now it should have 2 files only.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #13 on: 27 June 2009, 19:21 »
If I delete the folder I'll lose wp-postviews-widget.php. Does that matter?

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #14 on: 27 June 2009, 19:23 »
Before you do that, are you sure you are using WP-PostViews 1.50? because I see you are using WP 2.7.1. WP-PostViews 1.50 is meant for WP2.8, so either one of your info is wrong. 1.50 will break with WP 2.7

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #15 on: 27 June 2009, 19:27 »
Crap, I'm still on 2.7.1 because I was waiting for a 2.8 "dot" release (i.e. bug fixes).

When I saw your plugin was updated I simply did the automatic upgrade when it came out.

What now?  :-\

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #16 on: 27 June 2009, 19:30 »
I am surprise WP-PostViews 1.50 does not break for you on 2.7.1, it will throw you a class WP_Widget not found error.

In that case, replace the get_most_viewed() function with this

Code: [Select]
### Function: Display Most Viewed Page/Post
if(!function_exists('get_most_viewed')) {
function get_most_viewed($mode = '', $limit = 10, $chars = 0, $display = true) {
global $wpdb;
$views_options = get_option('views_options');
$where = '';
$temp = '';
$output = '';
if(!empty($mode) && $mode != 'both') {
$where = "post_type = '$mode'";
} else {
$where = '1=1';
}
$most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date < '".current_time('mysql')."' AND $where AND post_status = 'publish' AND meta_key = 'views' AND post_password = '' ORDER  BY views DESC LIMIT $limit");
if($most_viewed) {
foreach ($most_viewed as $post) {
$post_views = intval($post->views);
$post_title = get_the_title($post);
if($chars > 0) {
$post_title = snippet_text($post_title, $chars);
}
$post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);
$temp = stripslashes($views_options['most_viewed_template']);
$temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp);
$temp = str_replace("%POST_TITLE%", $post_title, $temp);
$temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp);
$temp = str_replace("%POST_CONTENT%", $post->post_content, $temp);
$temp = str_replace("%POST_URL%", get_permalink($post), $temp);
$output .= $temp;
}
} else {
$output = '<li>'.__('N/A', 'wp-postviews').'</li>'."\n";
}
if($display) {
echo $output;
} else {
return $output;
}
}
}

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #17 on: 27 June 2009, 20:03 »
My mistake, I apologize. I am on 1.4 and not 1.5. Will this code change be OK for 1.4?

It seems to work.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #18 on: 27 June 2009, 20:55 »
Should be =) I have not tested it on 2.7, my dev machine is 2.8

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline jschodde

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Calling get_most_viewed() with Sniplets plugin...
« Reply #19 on: 27 June 2009, 21:19 »
I'll run with it. thanks for your help  ;D