0
votes

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.

2
which one of this lines is 163? - aidinMC
@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ı
i edited the code you can look up - Eren Arıcı

2 Answers

1
votes

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' ) : '';
1
votes

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' ) : '';