[wp-trac] [WordPress Trac] #32290: Problem wpdb->update and update_post_meta
WordPress Trac
noreply at wordpress.org
Thu May 7 15:44:09 UTC 2015
#32290: Problem wpdb->update and update_post_meta
--------------------------+------------------------------
Reporter: mwanteam | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.2.2
Severity: normal | Resolution:
Keywords: close | Focuses:
--------------------------+------------------------------
Changes (by SergeyBiryukov):
* keywords: => close
Old description:
> 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
New description:
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
}}}
--
Comment:
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32290#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list