[Resolved] GP Premium plugin breaking custom code

Home Forums Support [Resolved] GP Premium plugin breaking custom code

Home Forums Support GP Premium plugin breaking custom code

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1657140
    Aleksey

    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);
    #1657177
    Leo
    Staff
    Customer Support

    Hi 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?

    #1657225
    Aleksey

    Hi Leo!

    Yes, when I’m disabling GP Premium the code working properly.

    I placed this code in content-single.php.

    #1657237
    Leo
    Staff
    Customer Support

    It’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/

    #1657239
    Aleksey

    I use child theme

    #1657245
    Leo
    Staff
    Customer Support

    Hmm 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-modules

    If not, then reactivate the modules one by one and see which module is causing the issue.

    #1657255
    Aleksey

    “Elements” this module is causing a trouble.

    #1657257
    Leo
    Staff
    Customer Support

    So what elements have you added?

    The module itself cannot cause an issue like this – it’s likely something that you’ve added in elements.

    #1657260
    Aleksey

    Just what was imported with a site from library: https://prnt.sc/ze8w6h

    #1657264
    Leo
    Staff
    Customer Support

    Can 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.

    #1657273
    Aleksey

    This 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>
    #1657299
    Leo
    Staff
    Customer Support

    Can you try adding your code using a hook element first?

    #1658454
    Aleksey

    I’ve disabled element, which was responsible for custom navigation inside the post and everything OK now.

    Thank you for the help!

    #1659416
    Leo
    Staff
    Customer Support
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.