[wp-trac] [WordPress Trac] #14568: adjacent_posts_rel_link_wp_head causes meta to be updated multiple times
WordPress Trac
wp-trac at lists.automattic.com
Mon Aug 9 09:23:26 UTC 2010
#14568: adjacent_posts_rel_link_wp_head causes meta to be updated multiple times
--------------------------+-------------------------------------------------
Reporter: greenshady | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.0.1
Severity: normal | Keywords:
--------------------------+-------------------------------------------------
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.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14568>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list