0

I'm getting an error while running view counter:

Warning: A non-numeric value encountered in C:\xampp\htdocs\tepetaklak\wp-content\themes\gridlove\core\template-functions.php on line 163

Here is the code :

case 'views':
                global $wp_locale;
                $thousands_sep = isset( $wp_locale->number_format['thousands_sep'] ) ? $wp_locale->number_format['thousands_sep'] : ',';
                if ( strlen( $thousands_sep ) > 1 ) {
                    $thousands_sep = trim( $thousands_sep );
                }
/*line163*/ $meta = function_exists( 'ev_get_post_view_count' ) ?  number_format_i18n( absint( str_replace( $thousands_sep, '', ev_get_post_view_count( get_the_ID() ) ) + gridlove_get_option( 'views_forgery' ) ) )  . ' '.__gridlove( 'views' ) : '';
                break;

Thanks for support.

Samvel Aleqsanyan
  • 2,812
  • 4
  • 20
  • 28
Eren Arıcı
  • 749
  • 1
  • 6
  • 12
  • which one of this lines is 163? – aidinMC Apr 07 '18 at 16:16
  • @aidinMC $meta = function_exists( 'ev_get_post_view_count' ) ? number_format_i18n( absint( str_replace( $thousands_sep, '', ev_get_post_view_count( get_the_ID() ) ) + gridlove_get_option( 'views_forgery' ) ) ) . ' '.__gridlove( 'views' ) : ''; break; – Eren Arıcı Apr 07 '18 at 16:20
  • i edited the code you can look up – Eren Arıcı Apr 07 '18 at 16:21
  • 1
    Possible duplicate of [Warning: A non-numeric value encountered](https://stackoverflow.com/questions/42044127/warning-a-non-numeric-value-encountered) – Samvel Aleqsanyan Apr 07 '18 at 16:38

2 Answers2

1

Try this: (cast string to int)

$num = (int) (str_replace( $thousands_sep, '', ev_get_post_view_count( get_the_ID() ) )) + (int)(gridlove_get_option( 'views_forgery' ));
$meta = function_exists( 'ev_get_post_view_count' ) ?  number_format_i18n( absint( $num ) )  . ' '.__gridlove( 'views' ) : '';
aidinMC
  • 1,415
  • 3
  • 18
  • 35
  • @ErenArıcı your welcome, if this answer did help you , please check it as true answer (below votes) – aidinMC Apr 07 '18 at 17:10
1

Have you install php7.1 or greater?

From what type is gridlove_get_option( 'views_forgery' ) ?

And you must convert the result from str_replace to an integer, if you use php7.1 or greater.+ Edit:

Your code should like this

$meta = function_exists( 'ev_get_post_view_count' ) ?  number_format_i18n( absint( (int)str_replace( $thousands_sep, '', ev_get_post_view_count( get_the_ID() ) ) + (int)gridlove_get_option( 'views_forgery' ) ) )  . ' '.__gridlove( 'views' ) : '';
Cyperghost
  • 63
  • 1
  • 8