Posts duplicated in categories

Forums Forums Menus Posts duplicated in categories

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1171
    buncle
    Member

    I have some subcategories which all have the same parent category, each with their own posts. When the categories are displayed in the PixoPoint menu, they are duplicated both in their correct subcategory *and* the parent category.

    Example:

    Parent
      – SubCategory A
          – Cat A Page 1
          – Cat A Page 2
          – Cat A Page 3
      – SubCategory B
          – Cat B Page 1
          – Cat B Page 2
          – Cat B Page 3
      – SubCategory C
    [i:1n8he7ig]  – Cat A Page 1
      – Cat A Page 2
      – Cat A Page 3
      – Cat B Page 1
      – Cat B Page 2
      – Cat B Page 3[/i:1n8he7ig]

    (Those in italics I don’t expect to be there, as they aren’t directly children of ‘Parent’, but of the subcategories)

    Am I missing something obvious?

    Thanks in advance!

    #7535

    Weird. What settings are you using in the plugin for the categories.

    #7536
    buncle
    Member

    Dropdowns: Infinite
    Empty categories? Yes
    Single dropdown? No
    Show child posts? Yes

    I have found a fix, however I’m not sure whether it is the correct way to go about it…

    Inside core.php within the categories_and_posts function, I have added the following code:

    [font=courier:3e6yjajm]foreach($posts as $current_post){
    [i:3e6yjajm][b:3e6yjajm]if ($current_post->post_parent == $category->cat_ID)
    {[/b:3e6yjajm][/i:3e6yjajm]
    echo '<li class="post-item post-item-' . $current_post->ID . '"><a href="' . get_permalink($current_post->ID) . '" title="' . $current_post->post_title . '">' . $current_post->post_title . "</a></li>";
    [i:3e6yjajm][b:3e6yjajm]}[/b:3e6yjajm][/i:3e6yjajm]
    }[/font:3e6yjajm]

    (My changes [i:3e6yjajm][b:3e6yjajm]emboldened[/b:3e6yjajm][/i:3e6yjajm])

    #7537

    Thanks <img decoding=” title=”Smiley” />

    I need to get some urgent work done right now, but I’ll take a look at this later on and if your fix works I’ll commit it to the repository as a bug fix.

    If I don’t reply within the next 24 hours then it’s because I forgot about this. Just keep pestering me as this sounds like a legitimate bug report (most aren’t).

    #7538
    buncle
    Member

    Just a little more information for you ready for when you take a look into this…

    This issue only occurs when ‘Show Child Posts’ are enabled. This also seems to be a long standing WordPress issue/feature(?) too – http://en.forums.wordpress.com/topic/hiding-a-child-categorys-posts-when-a-parents-posts-are-displayed%5B/url:2o7dt68a%5D

    It seems the issue is down to ‘get_posts()’ returning posts from all descendant categories. By adding the condition above, it is working around the issue.

    I am incredibly new to WordPress and PHP is not my usual language, so I may be making some incorrect assumptions, but I suspect there may be a way of changing the post query to ensure that get_posts only returns posts of the current depth (which would negate the need for my workaround).

    (P.S. I’m happy to help by the way. I know how exasperating it can be providing support for your code. Also, by looking into problems myself, its helping me familiarise myself with WP and PHP <img decoding=” title=”Smiley” /> )

    #7539
    buncle
    Member

    (Just spotted… my workaround it flawed. I’m using $category->cat_ID outside of the scope where $category is defined. Looking at an alternative now)

    #7540
    buncle
    Member

    I believe I have found a correct fix for this issue. Instead of the workaround I mentioned earlier (which ended up being incorrect anyway), I have replaced the following line (in ‘categories_and_posts()’):

    $posts = ($parent ? get_posts("category=$parent&numberposts=-1") : array());

    with:

    $posts = ($parent ? get_posts(array(‘category__in’ => array($parent), ‘numberposts’ => ‘-1’,)) : array());

    The WordPress reference guide mentions that ‘category__in’ does *not* return grandchildren of the specified parent (which is the behaviour we want), however it seems that using ‘cat’ or ‘category’ does.

    Feel free to point out anything wrong with this. As I mentioned earlier, I’m still learning <img decoding=” title=”Smiley” />

    #7541
    buncle
    Member

    …Just chiming in with a quick 24hr reminder!  <img decoding=” title=”Wink” />

    #7542

    Out of time. Haven’t forgotten though.

    #7543
    Anonymous
    Member

    I can confirm this bug. Thanks so much for fixing it, buncle; I was about to go mad dealing with this terrible software (WordPress, that is, not the plugin).

    #7544
    Anonymous
    Member

    Buncle – I’m having the same issue where children are showing up multiple times. If I have a child in a level 3 menu the child shows up in level 1, level 2 and level 3. I’m wondering if you found a final work around that you’d recommend for me.

    Thanks much
    Bob

    &quot;buncle&quot; wrote:
    I believe I have found a correct fix for this issue. Instead of the workaround I mentioned earlier (which ended up being incorrect anyway), I have replaced the following line (in ‘categories_and_posts()’):

    $posts = ($parent ? get_posts("category=$parent&numberposts=-1") : array());

    with:

    $posts = ($parent ? get_posts(array(‘category__in’ => array($parent), ‘numberposts’ => ‘-1’,)) : array());

    The WordPress reference guide mentions that ‘category__in’ does *not* return grandchildren of the specified parent (which is the behaviour we want), however it seems that using ‘cat’ or ‘category’ does.

    Feel free to point out anything wrong with this. As I mentioned earlier, I’m still learning <img decoding=” title=”Smiley” />

    #7545
    Anonymous
    Member

    Is there a good fix for this issue yet?

    #7546

    The latest beta should fix that issue:
    https://geek.hellyer.kiwi/pixopoint-menu-plugin-beta-0-8/

    If it doesn’t, please let me know <img decoding=” title=”Smiley” />

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