Site logo

Archived topic

GP Premium plugin breaking custom code

13 replies · Started by Aleksey on February 13, 2021

Viewing posts 1–14 of 14

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

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?

Hi Leo!

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

I placed this code in content-single.php.

I use child theme

"Elements" this module is causing a trouble.

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.

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.

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>

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

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

Thank you for the help!

No problem :)

This archived topic is closed to new replies.