Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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:


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):

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.

Change History (3)

#1 @demetris
8 years ago

This reminds me of:

Are you testing with Firefox? (Firefox, by default, prefetches REL links with value NEXT.)

#2 @greenshady
8 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Yep, it looks like it's an issue with Firefox prefetching the next links.

For this particular scenario, I went with an AJAX solution, which seems to work because the JavaScript isn't prefetched.

#3 @scribu
8 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.