Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I really didnt know what a proper title for this question could be.

Anyways, I have this code in functions.php which is breaking my site

function wp_show_post_views(){
global $post;
$postid = $post->ID;
$output_views = get_transient('views' . $postid);
if( !is_object( $post ) || true === $output_views ) return;
if( function_exists( 'stats_get_csv' ) ){
    $args = array(
          'days'  => -1,
          'post_id'  => $postid
     );
     $postviews = stats_get_csv( 'postviews', $args );
     $output_views = $postviews['0']['views'];

    update_post_meta($post_id, 'postviews', $output_views);
    set_transient('views' . $postid ,$output_views,60*60);
}
echo $output_views;
} 

I am calling it in my single.php as follows:

<?php wp_show_post_views(); ?>

In the front end, everything looks good. However, if I go to the backend and update some widgets, there are no changes in the front end. Once I remove the code, everything works fine.

So, I hope someone can tell me what is wrong with the code and if there is a way to fix it.

EDIT: I narrow it down to this:

            $args = array(
              'days'  => -1,
              'post_id'  => $postid
         );
         $postviews = stats_get_csv( 'postviews', $args );
         $output_views = $postviews['0']['views'];

So, the error must be in there.

EDIT: After enabling WP_DEBUG, I get his:

[18-Sep-2013 19:44:36 UTC] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/user/public_html/domain.com/wp-includes/functions.php:2998) in /home/user/public_html/domain.com/wp-content/plugins/jetpack/modules/stats.php on line 433
[18-Sep-2013 19:44:36 UTC] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/user/public_html/domain.com/wp-includes/functions.php:2998) in /home/user/public_html/domain.com/wp-content/plugins/jetpack/modules/stats.php on line 434

EDIT: Found more erorrs:

[18-Sep-2013 20:02:51 UTC] PHP Notice:  Trying to get property of non-object in /home/user/public_html/domain.com/wp-content/themes/2012.ffwd/functions.php on line 235

EDIT: This is line 235

    $postid = $post->ID;

I am also getting this error:

[18-Sep-2013 20:16:19 UTC] PHP Notice:  has_cap fue llamado con un argumento que está <strong>obsoleto</strong> desde la versión 2.0! El uso de niveles de usuarios por plugins y temas está obsoleto. Usa los perfiles y capacidades en su lugar. in /home/user/public_html/domain.com/wp-includes/functions.php on line 2998

Translated:

[18-Sep-2013 20:16:19 UTC] PHP Notice:  has_cap was called with an argument who are <strong> obsolete </ strong> since version 2.0! The use of user levels by plugins and themes is deprecated. Use the profiles and capabilities instead. in /home/user/public_html/domain.com/wp-includes/functions.php on line 2998
share|improve this question
    
Can you just check it for any errors by setting wp_debug to true in wp-config.php file? –  Vinod Dalvi Sep 18 '13 at 5:03
    
activate the defoult theme and then try to update –  Vikas Gautam Sep 18 '13 at 5:09
    
@Vinod Dalvi: I enabled wp_debug but I see no errors. Vickey: if I activate any other theme, it works again. Anyways, the site works if I disable the function. But I need to make that function work. –  Gixty Sep 18 '13 at 16:52
2  
Is is possible that the error exists within the stats_get_csv() function. Again, enable error reporting. In your functions.php file at the very top add error_reporting(E_ALL); –  Chris Sep 18 '13 at 18:26
1  
Is there a ?> at the end of your functions.php file? If so, try removing it. There may be whitespace characters after it, which you don't want. –  Pat J Sep 18 '13 at 19:55
show 9 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.