Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#4913 closed defect (bug) (fixed)

Future posts cause term count to increase

Reported by: otto42's profile Otto42 Owned by:
Milestone: 2.5 Priority: normal
Severity: major Version: 2.3
Component: General Keywords:
Focuses: Cc:

Description

Making a future post causes the term counts to increase for both tags and categories, which makes the displayed counts for either of these incorrect, when using wp_list_categories or similar functions with the "show_count" option.

Correct behavior would be for counts to ignore future posts, since they have not been published yet. This would require the wp_update_term_count function to take post_status into account and would require the wp_publish_post to call wp_update_term_count as well (possibly through a post transition action or some such thing).

Attachments (2)

4913.diff (632 bytes) - added by ryan 17 years ago.
Update term counts when future post is published
future_count.diff (651 bytes) - added by ryan 17 years ago.

Download all attachments as: .zip

Change History (12)

#1 @MichaelH
17 years ago

It seems the only way counts 'work' for future posts is to edit and save the post after it is published.

At 7:15, Write a new post. Create new tag called 730tag, and add new category called 730cat and attach to post. Edit timestamp and set to 7:30 future time, and finally, click on Publish.

At 7:20, the post is not yet shown on the blog. The Tag Cloud widget, and the Category widget (with no boxes checked), do not present either the new tag or category. With no Widgets active, but in sidebar.php using wp_tag_cloud('') the 730tag is not seen. Using wp_list_categories('hide_empty=0&show_count=1') the 730cat is shown with a count of zero (0). MySQL table wp_term_taxonomy reflects both the new tag and the new category, and the count field is zero (0) in both cases.

At 7:30, the post publishes and is visible on the blog.

At 7:45, the 730tag, using the_tags('Tags: ', ', ', '<br />'), and the 730cat, using php the_category(', '), are shown with the post.

Now this is where the problem is!! At 7:45, the Tag Cloud widget, and the Category widget (with no boxes checked), do not present EITHER the 730tag or the 730cat. With no Widgets active, but in sidebar.php using wp_tag_cloud('') the 730tag is NOT seen. Using wp_list_categories('hide_empty=0&show_count=1') the 730cat is shown with a count of one (1). MySQL table wp_term_taxonomy still reflects both the new tag and the new category, and the count field is STILL zero (0) in both cases.

At 8:00, edit the post, make a change to the content, and save. This edit/save seems to set things straight.

At 8:05, the Tag Cloud widget, and the Category widget (with no boxes checked), show both the 730tag or the 730cat. With no Widgets active but using wp_tag_cloud('') the 730tag is SEEN. Using wp_list_categories('hide_empty=0&show_count=1') the 730cat is shown with a count of one (1). MySQL table wp_term_taxonomy the count field for the category is NOW one (1), the count for the post_tag record is STILL zero (0).

Thanks to sspelta on http://wordpress.org/support/topic/139234 for pointing this out.

@ryan
17 years ago

Update term counts when future post is published

#3 @ryan
17 years ago

Here's an untested patch. It should update counts for all of the post's terms when the post is published.

#4 @MichaelH
17 years ago

The 4913.diff doesn't seem to fix the problem in 2.4-bleeding.

When the post gets published, neither the Tag Cloud widget or the Category widget reflect the tag or the category. Using wp_tag_cloud('') in sidebar.php shows no value. Using wp_list_categories('hide_empty=0&show_count=1') in sidebar.php shows zero (0) count for the category.

The WordPress Default 1.6 theme's index.php, using the_tags('Tags: ', ', ', '<br />') and the_category(', '), DOES show the tag and category.

Editing and saving the post does 'fix' the counts, including showing the proper value in the count field in term_taxonomy for both tag and category.

Looks like the same results with 2.3 when the fix is put into the line 831 area of wp-includes/post.php.

#6 @JDTrower
17 years ago

I was able to reproduce the original problem following the information given. The only change was after I edited the post, my MySQL table wp_term_taxonomy showed the count field for the category as one (1) and the count for the post_tag record as one (1) as well. Whereas, the original poster showed the count for the post_tag record as zero (0). Implementing the posted patch didn't solve the problem in 2.4-bleeding.

#7 @ryan
17 years ago

wp_get_object_terms($post_id, $taxonomy);

should be:

wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');

@ryan
17 years ago

#8 @ryan
17 years ago

Fresh patch that works for me.

#9 @ryan
17 years ago

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

(In [6425]) Update term counts when future posts are published. fixes #4913 #5488

#10 @JDTrower
17 years ago

I know this was already committed, but just thought I would verify that the patch worked for me, I must have introduced a glitch when I manually changed the code.

Note: See TracTickets for help on using tickets.