Support » Fixing WordPress » update_post_meta updates 2 posts

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try moving the code inside the loop in content-page.php and content-single.php.

    Or try in header.php:

    if( is_singular() ) {
      global $post;
      $views = get_post_meta($post->ID, 'gp_file_views', true) ? get_post_meta($post->ID, 'gp_file_views', true)++ : 1;
      update_post_meta($post->ID, 'gp_file_views', $views);



    I tried moving the code into both content-page.php and the header (not at the same time, of course) and it still happens. This is really stumping me. I’ve used get_post_meta and update_post_meta many times in the past without issue.

    Anyone have any other suggestions? Thanks!

    I have tested this with a Twenty Eleven child theme and here is what is happening:
    Choose a post in the list and View Counter + 1
    Previous post navigation and View Counter + 1
    Next post Navigation and the View Counter + 2

    So the double view counter is when you press “Next” it must resend the page or post.

    Looks like it is a core function issue, maybe reduce the counter in the function for next post, this will depend on the theme, and if it is a bug that is updated later in the core, search Trac?



    It’s not increasing the view count by 2. It’s increasing it by 1 but also increasing the view count of the following post. I’m not viewing the posts via navigation.

    If I select a post with post ID 5, and the next post has ID 11, they both increase by one. But if I have a post with ID 13, it’s not affected unless I select post 11, then 13 is increased as well.

    Also, it occurs even if I copy and paste the link directly into the address bar. No matter what I do, it increases BOTH posts.

    I even tried giving the post a unique meta key by appending the post’s ID to the meta key, but it still does it.

    Okay, so I’ve dug a little deeper into this problem and here’s what I’ve found:

    It has nothing to do with my code, but instead Firefox is running the page twice.

    I found a solution here.

    Thanks for your time and help!

    No Problem, I was testing with FireFox, never thought to try another browser.

    For anyone else that might read this topic, we were on the right track with the next post, it was being pre-loaded by FireFox.

    From the linked topic:

    //remove auto loading rel=next post link in header
    remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');


    I am working with custom post types a custom meta values for managing a banner rotator area in my theme.

    I insert each banner as a post with “custom post type” and then when a banner loads I’m tryng to “update_post_meta” for subtracting in the views limit meta wich I call “_printsleft”

    The thing is that when I was using “update_post_meta” in FIREFOX two of my banners was being updated… I noted that in some cases the same banner was uptaded twice so the “_printsleft” was being substracted two times.

    So in my case the update_post_meta isn’t happening in the next post unless in any random banner including the same banner.

    I tried the remove action adjacent_posts_rel_link_wp_head but it doesn’t fix the problem in firefox…

    in chrome my banners are sustracting its custom meta “_printsleft” correctly.

    please help!!

    Here is a possible solution suggested by my friend

    I will try to update_post_meta “_printsleft” only via ajax. The non-javascript user will be loosing my ads but I really need to update_post_meta right firefox!!

    ok, I’ll came back with news later

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘update_post_meta updates 2 posts’ is closed to new replies.