• Hello, after updating the plugin on some pages, the counter does not work correctly or does not work at all

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author dFactory

    (@dfactory)

    What is your counter method?
    Do you have any Javascript issues in the frontend?
    Can you share your site URL?

    Plugin Author dFactory

    (@dfactory)

    Are you using latest version of the plugin?
    What is your counter method?
    Did you try changing this?

    The issue is coming from this code related to the shortcode implementation

    // main item?
    if ( ! in_the_loop() ) {
        // get current object
        $object = get_queried_object();
    
        // post?
        if ( is_a( $object, 'WP_Post' ) ) {
            $defaults['id'] = $object->ID;
            $defaults['type'] = 'post';
        // term?
        } elseif ( is_a( $object, 'WP_Term' ) ) {
            $defaults['id'] = $object->term_id;
            $defaults['type'] = 'term';
        // user?
        } elseif ( is_a( $object, 'WP_User' ) ) {
            $defaults['id'] = $object->ID;
            $defaults['type'] = 'user';
        }
    }

    When using the shortcode on pages that are not archive ones or on places where we don’t have loops, the correct Post ID gets overridden by $object = get_queried_object(); and $defaults['id'] = $object->ID;. This is causing all post counts across the page to have the same count number as the queried post – the one that the user is currently on.

    You need to fix the code after // main item? part.

    The temporary workaround for all that have the same issue would be to use the pvc_post_views_html filter like this:

    add_filter( 'pvc_post_views_html', 'custom_pvc_post_views_html', 10, 5 );
    /**
     * It replaces the number of views in the Post Views Counter plugin with the number of views in the
     * Post Views plugin
     * 
     * @param html The HTML to be filtered.
     * 
     * @return the html.
     */
    function custom_pvc_post_views_html( $html ) {
    	if ( ! function_exists( 'pvc_get_post_views' ) ) {
    		return $html;
    	}
    
    	$views = pvc_get_post_views();
    
    	$html = preg_replace( '/<span class="post-views-count">(.*?)<\/span>/', '<span class="post-views-count">' . $views . '</span>', $html );
    
    	return $html;
    }

    The alternative option would be to use the pvc_get_post_views function and pass a post ID to it

    Thread Starter texas1907

    (@texas1907)

    @vabrashev Thank you

    Thread Starter texas1907

    (@texas1907)

    @vabrashev Hello, please tell me how to get the most viewed posts in 7 days?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘problems after plugin update 1.3.12’ is closed to new replies.