#14568 closed defect (bug) (invalid)
adjacent_posts_rel_link_wp_head causes meta to be updated multiple times
Reported by: | greenshady | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
I wasn't exactly sure what to title this ticket as I'm not certain *what* causes the issue. But, I can tell you how I found it and the solution I'm currently using to fix it. Maybe someone can help me track it down.
I was writing a post views function that tracks the number of times single posts have been viewed using the post meta functions. Here's a loook at it:
add_action( 'template_redirect', 'entry_views_update' ); // Tried many different hooks function entry_views_update() { global $wp_query; if ( is_singular() ) { $post_id = $wp_query->get_queried_object_id(); $old_views = get_post_meta( $post_id, 'Views', true ); $new_views = absint( $old_views ) + 1; update_post_meta( $post_id, 'Views', $new_views, $old_views ); } }
This works great for the post being viewed. But, the problem is that the next post (one published after it) also gets an updated view count. So, two posts are getting their meta updated when only the current post meta should be updated.
I ran across two other topics where others had the same issue (there may be more):
- http://wordpress.org/support/topic/problem-with-add_filter-while-developing-a-plugin
- http://wordpress.org/support/topic/assistance-with-update_post_meta-issue
The only solution that seems to work is adding this:
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 );
This removes the next/prev posts from the <head>
area, which is not desirable.
This reminds me of:
Are you testing with Firefox? (Firefox, by default, prefetches REL links with value NEXT.)