Support » Fixing WordPress » Trying to output one post from each category need to avoid duplicates

  • Resolved matt-tyas


    Hi and thanks in advance for any help.

    I am running this basic query in my loop file to output one post from each category and sub-category:

    Code in pastebin:

    And so on for about 20 categories.

    The issue is the posts are sometimes in multiple categories and this is causing duplicates on the homepage. What can I add to stop this duplication?

    Thanks again.


Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael


    Forum Moderator

    the method to avoid duplicate posts in multiple looops is described here (the ‘array’ method after the ‘Note for Multiple Posts in the First Category’ headline):

    do you have the code to show all your categories with one post?


    That is the page I was (trying) to follow instructions on by using:

    $do_not_duplicate = $post->ID;

    I understand I am probably using it incorrectly as I am not much good at PHP. I want to show the latest post from each category and sub category. As you can see currently on my homepage – there are a lot of duplicates. I am trying to eradicate these. So if a post has already been displayed then it appears in another category, it will be skipped over and the next newest will be shown.

    I hope that makes sense.

    A longer pastebin is here:

    Thank you



    Forum Moderator

    I particularly pointed to the ‘array method’ – have you read the linked codex chapter and tried to implement it?

    here is a partly corrected section of your code, to show the principle:

    Thank you I will give this a go and get back to you, with good or not as good news.

    Hi, it looks like that has worked for me, many thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Trying to output one post from each category need to avoid duplicates’ is closed to new replies.