• Resolved catuyen

    (@catuyen)


    Hello

    A previous developer helped me write this function to get the post view from REHUB theme and display it in another plugin as a shortcode. It works but when I turn on debug, there are a lot of warnings.

    Code

    function custom_get_view_post( $attrs, $content ) {
    	if(rehub_option('post_view_disable') != 1 && function_exists('RH_get_post_views')){
    	    $post_id = get_the_ID();
    	    $views = intval(RH_get_post_views($post->ID));
    	    return $views;
    	}else{
    		return "";
    	}
     }
    
    // add template tag for w4 post list
    add_filter( 'w4pl/get_shortcodes', 'custom_product_shortcodes', 20 );
    function custom_product_shortcodes( $shortcodes ) {
        $shortcodes['views'] = [
            'group' 	=> 'Post', 
    		'callback' 	=> 'custom_get_view_post',
    		'desc' 		=> '<strong>'. __('Output', 'text-domain') .'</strong>'
        ];
    
        return $shortcodes;
    }
    

    Warnings

    Warning: Undefined variable $post in /home/mysites/web/mydomain.com/public_html/wp-content/themes/rehub-blankchild/functions.php on line 26

    Warning: Attempt to read property “ID” on null in /home/mysites/web/mydomain.com/public_html/wp-content/themes/rehub-blankchild/functions.php on line 26

    Could some expert here please help me correct this code??

    Thank you so much!
    CU

    • This topic was modified 2 years, 11 months ago by catuyen.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘A lot of warnings from the code, please help’ is closed to new replies.