• The following error happens when the plugin is activated:

    Notice: Undefined index: postviews_id in /mounted-storage/path-to-my-wp/wp-content/plugins/wp-postviews/wp-postviews.php on line 648

    I tried to fix it but I made it even worst, so I decided to raise this topic. The following piece of code is where the error happens, in acord of the error above:

    ### Function: Increment Post Views
    increment_views();
    function increment_views() {
    	global $wpdb;
    	$post_id = intval($_GET['postviews_id']);
    	if($post_id > 0 && defined('WP_CACHE') && WP_CACHE) {
    		$post_views = get_post_custom($post_id);
    		$post_views = intval($post_views['views'][0]);
    		if(!update_post_meta($post_id, 'views', ($post_views+1))) {
    			add_post_meta($post_id, 'views', 1, true);
    		}
    	}
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Lester Chan

    (@gamerz)

    notices are harmless but it is a bad practice for my part to code with notices off. Google how to off notices in php

    Hi !
    I have the same issue because I develop with WP_DEBUG at true, you can fix this like this :

    function increment_views() {
    	global $wpdb;
    	if( !isset($_GET['postviews_id'] ) )
    		return false;
    	$post_id = intval($_GET['postviews_id']);
    	if($post_id > 0 && defined('WP_CACHE') && WP_CACHE) {
    		$post_views = get_post_custom($post_id);
    		$post_views = intval($post_views['views'][0]);
    		if(!update_post_meta($post_id, 'views', ($post_views+1))) {
    			add_post_meta($post_id, 'views', 1, true);
    		}
    	}
    }

    Seems to work and not blocking the plugin ??

    can someone help me?

    I was updating plugins and something happened. My website and backend have these notices such as

    Notice: Undefined index: path in /data/xx/user/xx/htdocs/wp-content/plugins/custom-permalinks/

    a) how do I fix the code
    b) is it possible for all of these notices to be removed by turning off debug error reporting in wp-config?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘postviews_id is an Undefined Index’ is closed to new replies.