WordPress.org

Forums

[resolved] Trying to output one post from each category need to avoid duplicates (6 posts)

  1. matt-tyas
    Member
    Posted 3 years ago #

    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: http://pastebin.com/srwgpWN6

    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.

    Matt

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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): http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

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

  3. matt-tyas
    Member
    Posted 3 years ago #

    Hi,

    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 - http://www.manchesterfinest.com 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: http://pastebin.com/KeiYZWm2

    Thank you

  4. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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:
    http://pastebin.com/hv0vjzye

  5. matt-tyas
    Member
    Posted 3 years ago #

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

  6. matt-tyas
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic