Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#32290 closed defect (bug) (invalid)

Problem wpdb->update and update_post_meta

Reported by: mwanteam's profile mwanteam Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2.2
Component: General Keywords: close
Focuses: Cc:

Description (last modified by SergeyBiryukov)

I'm developing plugins and wordpress theme for my private project. To the point, i have found problem about "wpdb->update and update_post_meta".

The update result (on database) is incorrect when i use increment variable.
Example: I build viewPageCounter function, so in single.php I update the meta_value (of the post_views_count column) with countered or increment variable.But the result is always +1 (more 1 point from the true result).

But after i remove the rel='prev' and rel='next' on wp_head() using remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); the result is correct.

First trial, i use

$count = get_post_meta('20', $count_key, true); //example the $count is 11
$count++; //to be 12
update_post_meta('20', 'post_views_count', $count); //on database is 13

2nd trial, i use $wpdb->get_results and $wpdb->update, I got the same result.

Finally i trace and got the problem is on wp_head() in rel=next. So after remove it using remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); i got the correct result

$count = get_post_meta('20', $count_key, true); //example the $count is 11
$count++; //to be 12
update_post_meta('20', 'post_views_count', $count); //on database is 12

Change History (3)

#1 @SergeyBiryukov
9 years ago

  • Description modified (diff)
  • Keywords close added

Hi @mwanteam, welcome to Trac!

It's caused by browser prefetching, see #12603, #14382, #19018, #20192, #21658, #28797.

I don't think we can do anything here.

#2 @Jessy Marco
9 years ago

Yes, it doesn't work.

Similarly reported: #33223

Last edited 9 years ago by SergeyBiryukov (previous) (diff)

#3 @SergeyBiryukov
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

See comment:1.

Note: See TracTickets for help on using tickets.