Support » Plugin: Post Views Counter » Not working at all
Not working at all
-
Hi, I am trying to show post views on my website. I have a custom post type in which I add custom taxonomies and I add your code
<?php echo do_shortcode('[post-views]'); ?>
to my filetaxonomy-name
and it’s not working, nothing to showing me.
-
is this plugin alive ?
Question is where you add this shortcode? It has to reside inside a posts loop so that it gets data from a post.
Otherwise you can try using a function and passing a post ID to it (please check functions.php plugin file to see the functions you have available)I don’t have the loop, and I don’t have any code in my function file.
I am having about the same problem.
Post views are displayed when I am connected only…Hello, any help?
In order to display the views you need to pass post ID. The shortcode assumes that it is used in a loop of posts because this is where the post object is always present https://codex.wordpress.org/The_Loop.
If you use the shortcode outside of a loop it will not work – there is no post ID for which to get the views.
In order to get the views anywhere you want you can use a function (that is located in functions.php file in the plugin folder) – pvc_get_post_views( $post_id ). This function accepts one parameter – post ID. If you pass it like pvc_get_post_views( 123 ) you will get the views count for post 123.
Hope this helps,
how i can display on tag archive page. let say i have a url
https://mydomain.com/tag/counter
And there is no post inside, I add only HTML to this URL. So what is the way to show views on this URL?
This is my code in custom taxonomy file (taxonomy-tv_channels.php)
<?php get_header(); ?> <h1><?php $taxonomy = get_queried_object(); echo $taxonomy->name; ?> Live Tv Online</h1>
https://www.youtube.com/watch?v=<?php the_field('url'); ?><!--VIEWS--> <?php echo do_shortcode('[post-views]'); ?> Views <?php get_footer(); ?>As you can see that I added the post views code inside but not working at all. If I use a loop then it messes up the page.
-
This reply was modified 3 months, 1 week ago by
Xaib Aslam.
-
This reply was modified 3 months, 1 week ago by
Xaib Aslam.
Also i try to search and found this, so how i can make it work with your plugin.
function my_count_views() { if ( is_category() ) { $views = intval( get_term_meta( get_queried_object_id(), 'category_views', true ) ); update_term_meta( get_queried_object_id(), 'category_views', $views + 1 ); } } add_action( 'template_redirect', 'my_count_views' );
If you are using shortcode, the temporary workaround 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 instead of do_shortcode() and pass a post ID to it.
-
This reply was modified 3 months, 1 week ago by
Vladislav Abrashev.
now its not working in loop as well. i added code after this code
<?php while ( have_posts() ) : the_post(); ?>
-
This reply was modified 3 months, 1 week ago by
- You must be logged in to reply to this topic.