Support » Plugins and Hacks » Hacks » update_post_meta adds one to value

update_post_meta adds one to value

Viewing 4 replies - 1 through 4 (of 4 total)
  • I tested your code exactly as you posted it using update_post_meta() and commenting out the 2 query lines and it works as expected.

    Every time I refreshed the page the count updated by 1

    I added setPostViews( get_the_ID() ); inside the loop in single.php

    Thank you. That is good.

    Unfortunately, I am still getting the same result on my side. To further investigate, I put an echo statement in the update_post_meta function in wp-includes/posts.php.

    I echoed the meta_value argument and it gave me the bad value. That is: count had a value of 10, but the value that update_post_meta echoed was 11. So the problem occurs early on, between my php and wordpress’s php, but how? And not on your site… Seriously, I am witnessing the impossible!

    Grr. I have the workaround to use, and I generalized my query by using wpdb instead of identifying my table expressly. But I want the real code to work…Oh well, add it to my list of website mysteries.

    add_post_meta() ends up calling update_meta_data(), which has several hooks. I suspect some plugin is conflicting with your code via one of these hooks. You might try using a more unusual key than a generic “Views”, always good practice btw.

    Thanks everyone! I am finding a number of impossible issues with this wordpress install.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘update_post_meta adds one to value’ is closed to new replies.