post-page

How To: Avoid Duplicate Posts

28
responses
heading
heading
heading
28
Responses

 

Comments

  1. John Kolbert (23 comments.) says:

    Ronald, another enlightening post. Your knowledge of the loop is astounding. Maybe YOU should right the Codex :) Thanks for the great tutorial

  2. Gelay.j@gmail.com (1 comments.) says:

    Something to think about further. Thanx.

  3. Epic Alex (18 comments.) says:

    I’ve tried posting code a couple of times just now, and i keep getting some kind of spam error, so i’ll put the code in a pastebin.

    Basically I think there is a quicker and easier way of doing this, by storing the ids in an array and then searching that array in the second loop.

  4. johnbillion says:

    @Epic Alex

    Just glancing over your code it looks to me like if your second loop encounters duplicates then it will end up not showing the correct number of posts. Your code is removing the duplicate posts after five have been selected from the database. If two of those are duplicates, only the remaining three will be shown. If all five are duplicates, no posts will be shown!

    Do correct me if I’m wrong as I haven’t tested your code.

  5. Ronald Huereca (66 comments.) says:

    @Epic,
    Yes, that is an easier way of doing it, but say you want to display five posts. If there are two duplicates, then only three would be shown.

    @Johnbillion,
    You hit the nail on the head. That’s why I decided to modify the original query, which would return the correct number of posts without the duplicates.

    @All,
    As Epic pointed out, posting code here is problematic. I suggest using Pastebin and posting the link here. Thanks.

  6. Mark (1 comments.) says:

    Sorry about the posting code issue. Pastebin is the best option.

  7. BANAGO (84 comments.) says:

    Very helpful post for every wordpress coder.

  8. Nathan says:

    Thank you so much Ronald for this post – it has helped me greatly. I have come across a new problem however. When I click the “Previous Posts” link, it displays an error (see below) and then proceeds to display all my posts, including those already displayed. If I keep clicking “Previous Posts” it will even display posts not yet published, but in Draft mode, and also all my pages (Contact, About).

    The error I get:

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘post_strip’ was given in /../wp-includes/plugin.php on line 163

    I am using WordPress 2.5

    Also, my setup is a little different than your example loop. I display the last article from one author in one loop and save the ID. Then I have another loop that displays the last post from the other author, and it makes the variable = variable + new ID. Then I run the generic loop to display the last 5 posts excluding the two that have already been displayed. This is to feature the last post from each author at the top. Just slightly different from your example. It works fine except for the navigation.

    TIA for any help.

  9. Nathan says:

    Just to clarify. I had incorrectly placed the code to remove the filter. Now that I have corrected that the problem is slightly different. When I click the “Previous Post” link, it still displays the error, and the chronologically lists the 5 last posts (not 6-10, but 1-5 from the first page). No “Previous Posts” link appears at the bottom of this 2nd page. In effect, it displays the first page all over again without the exclusions and then fails to display the navigation.

  10. Nathan says:

    Ronald emailed me and helped me out. See this article for help.

  11. MTB (1 comments.) says:

    Nice tutorial. How would you get three loops to work. Basically, in this order: Feature loop (1 post), Standard Loop (1 posts), Specific Category Loop (5 posts). I’m trying not to repeat content between the three loops. I have the Feature Loop and Standard loop working, I’m just not getting the third (Specific Category) loop to function. Thanks.

  12. Sajid Iqbal (2 comments.) says:

    My question is:
    Can I extend this to more than two loops and for a single category posts(displayed in 3 different blocks)?

  13. Sajid Iqbal (2 comments.) says:

    Any answer plz?

  14. Víctor says:

    Hi, great post.

    How I should do it, if I want to filter by Title, not by ID.

    Thanks



Trackbacks/Pingbacks

  1. […] – How To: Avoid Duplicate Posts [Wordpress] “Here’s how to show two individual [Wordpress] l loops without duplicating posts in either […]

  2. […] How To: Avoid Duplicate Posts (tags: wordpress) […]

  3. […] Avoid Duplicate Posts […]

  4. […] How to Avoid Duplicate Posts in the WordPress Loop – This post by Weblog Tools Collection explains how to avoid duplicate posts in both a single WordPress loop and a double WordPress loop. […]

  5. […] How to Avoid Duplicate Posts in the WordPress Loop – This post by Weblog Tools Collection explains how to avoid duplicate posts in both a single WordPress loop and a double WordPress loop. […]

  6. […] How To: Avoid Duplicate Posts, shows how to avoid duplicating multiple posts instead of single post. […]

  7. […] i provided here handles a single featured post. Thats why i provided a link to a nice solution by Weblog Tools Collection that shows how to avoid duplicating multiple […]

  8. […] Come evitare i contenuti duplcati […]

  9. […] How To: Avoid Duplicate Posts | Weblog Tools Collection […]

  10. […] How To Avoid Duplicate Posts […]

  11. […] next (and final) tip is actually something written by Ronalfy on WebLogToolsCollection a couple of years ago – and I now use it in all of my themes (Elemental, and Mimbo Pro both […]

Obviously Powered by WordPress. © 2003-2013

page counter
css.php