- This topic has 13 replies, 2 voices, and was last updated 3 years, 2 months ago by Leo.
-
AuthorPosts
-
February 13, 2021 at 10:39 am #1657140Aleksey
Hi!
Here is a code, which counts the number of views of the page.
GP Premium plugin doubles this number. So each time I’m checking the page counter adds 2 views instead of one.
Why is it happenning and how can I fix it?$views = get_field('views') ? get_field('views') : 0; $downloads = get_field('downloads') ? get_field('downloads') : 0; $views++; update_field('views', $views);
February 13, 2021 at 11:39 am #1657177LeoStaffCustomer SupportHi there,
I don’t see how GP Premium would cause an issue like this.
How are you adding the code?
Does the issue not happen when GP Premium is disabled?
February 13, 2021 at 12:06 pm #1657225AlekseyHi Leo!
Yes, when I’m disabling GP Premium the code working properly.
I placed this code in content-single.php.
February 13, 2021 at 12:10 pm #1657237LeoStaffCustomer SupportIt’s never a good idea to add or modify the theme’s templates as the changes will be erased through update.
Can you try adding it using one of the hooks element first?
https://docs.generatepress.com/article/hooks-element-overview/
https://docs.generatepress.com/article/hooks-visual-guide/February 13, 2021 at 12:11 pm #1657239AlekseyI use child theme
February 13, 2021 at 12:16 pm #1657245LeoStaffCustomer SupportHmm I still don’t see how GP Premium can cause this.
Can you disable all modules in GP Premium and see if the issue still exists?
https://docs.generatepress.com/article/installing-gp-premium/#activate-your-modulesIf not, then reactivate the modules one by one and see which module is causing the issue.
February 13, 2021 at 12:31 pm #1657255Aleksey“Elements” this module is causing a trouble.
February 13, 2021 at 12:33 pm #1657257LeoStaffCustomer SupportSo what elements have you added?
The module itself cannot cause an issue like this – it’s likely something that you’ve added in elements.
February 13, 2021 at 12:35 pm #1657260AlekseyJust what was imported with a site from library: https://prnt.sc/ze8w6h
February 13, 2021 at 12:36 pm #1657264LeoStaffCustomer SupportCan you disable each of them and try to determine which one is causing the issue?
I would also recommend trying to add that code using a hook element.
February 13, 2021 at 12:45 pm #1657273AlekseyThis one “Custom Post Navigation”. Here is code from this element:
<div id="post-nav"> <?php global $post; $prevPost = get_previous_post(false); $post_type = get_post_type(); if ( $prevPost ) { $args = array( 'posts_per_page' => 1, 'include' => $prevPost->ID, 'post_type' => $post_type, ); $prevPost = get_posts($args); foreach ($prevPost as $post) { setup_postdata($post); ?> <a class="post-previous" href="<?php the_permalink(); ?>"> <div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.1),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');"> <div class="post-nav"><?php _e( 'Previous', 'generatepress' ); ?></div> <h3 class="post-nav-title"><?php the_title(); ?></h3> </div> </a> <?php wp_reset_postdata(); } //end foreach } // end if $nextPost = get_next_post(false); if ( $nextPost ) { $args = array( 'posts_per_page' => 1, 'include' => $nextPost->ID, 'post_type' => $post_type, ); $nextPost = get_posts($args); foreach ( $nextPost as $post ) { setup_postdata($post); ?> <a class="post-next" href="<?php the_permalink(); ?>"> <div class="post-nav-wrap" style="background: linear-gradient(0deg,rgba(52,62,71,0.6),rgba(52,62,71,0.3)),url('<?php the_post_thumbnail_url(); ?>');"> <h3 class="post-nav-title"><?php the_title(); ?></h3> <div class="post-nav"><?php _e( 'Next', 'generatepress' ); ?></div> </div> </a> <?php wp_reset_postdata(); } //end foreach } // end if ?> </div>
February 13, 2021 at 1:25 pm #1657299LeoStaffCustomer SupportCan you try adding your code using a hook element first?
February 14, 2021 at 8:59 pm #1658454AlekseyI’ve disabled element, which was responsible for custom navigation inside the post and everything OK now.
Thank you for the help!
February 15, 2021 at 11:31 am #1659416LeoStaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.