Support » Fixing WordPress » multiplying categories

  • On the pages where I created The Loop with a $posts = get_posts('numberposts=xx'); foreach ($posts as $post) : start_wp(); I have started getting category names appearing multiple times with the posts with which they are associated. Thus, where a post might be in the “World News” category, the post has appended to it “World News, World News”. Prior to using the get_posts call I was not getting this error. Also, the error is not universal, but I cannot see a pattern for the ones affected and the ones not. Now some entries have 3 itterations of the category name while some have only the one.
    (I wanted to use the get_post tag so I could make two loops, one – above – to put a limited number of posts formatted in a particular way and the second – below – with just the titles of the article and their categories).
    The remainder of the pages that do not use get_posts are continuing to function normally.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Can you post a link to your index.php file saved as a .txt file? I’m curious as to see what you did. I have a suspision, but I want to wait to see how your file is laid out first.

    Hey, I’ll be honest…. I’m completely stumped. It looks like there is something in the call to the the_category() function that’s causing the categories to print multiple times. Coupled with the fact that they are all separated by commas as opposed to “cat1, cat2 cat1, cat” that the function thinks it’s doing it right.
    What makes it eve weirder, is that in the archives and single post and comments views, it all looks right! Gah! I have no freekin’ clue.
    Sorry I couldn’t be of any more help. Short of tearing apart wp-blog-header.php or template-functions-category.php and combing through it for any thing, I don’t know what else.

    update_post_caches() is called for both loops. Posts present in both loops will have their category list stuck in the category cache twice. It’s a bug. I’ll fix it tomorrow.

    Actually, if you check the output from the second get_posts loop, you will notice that the first 3 items are repeating three times. I suspect it is because the default number of posts per page is set to 10. I have no idea what the update_post_caches() might do, but there seem to be three loops, not just the two that are displayed on this page.
    1 – the default loop (set to 10)
    2 – the first get_posts loop (with date, title, excerpt, categories, etc) (set to 3)
    3 – the second get_posts loop (with just title, date & categories) (set to 15, but I only have 14)

    Uh, did this issue get addressed last week? I d-loaded the Mon, Oct 25 nightly and installed it in a separate directory, but it is doing the same thing. If it was addressed, it was not fixed. If it was not addressed, is there any further time-table for it?

    Does anyone know if the update_post_caches() was somehow changed to let two get_posts co-exist on the same page? If not, could this be worked around by off-loading each loop into an include file or would that still double (or triple) the category entries?

    It still needs to be fixed. I’ve been preoccupied. Anyone else can feel free to fix it and send a patch. You don’t have to wait on me. 😉

    Fixed in CVS thanks to some help from the hackers list.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.