WordPress.org

Ready to get started?Download WordPress

Forums

Excluding some posts (4 posts)

  1. guigouz
    Member
    Posted 6 years ago #

    Hello!
    The example shown to exclude some posts on the query_posts() documentation uses a list of excluded posts inside the loop, which is pretty ugly, as if I have shown 4 "special" posts before (imagine a "special" category) and want to show 10 posts later (any category), I'd have to bring 14 posts to make sure all will get shown.

    Is there any way to tweak the query beyond query_posts() (where ID NOT 1 and ID NOT 2 and ID NOT 3 and so on) ?

    Thanks a lot

    gui

  2. Chris_K
    Member
    Posted 6 years ago #

    Have you considered using category to determine what to exclude?

    Here's a plugin that might help?
    http://wordpress.org/extend/plugins/advanced-category-excluder/

  3. guigouz
    Member
    Posted 6 years ago #

    I have a "Special" category, on which I query 4 posts to appear in a different layout on the front page. After that, I must show all posts (from all categories), but not the 4 posts I already showed.
    Currenty, I'm keeping track of the post ids I showed, and then, I fetch max_posts + 4 from the database, and don't display if the_ID was already displayed.
    I know this can be done in a much cleaner manner using sql directly, but haven't found a way to tweak wordpress queries in such a low level.

    Any tips ?

  4. Chris_K
    Member
    Posted 6 years ago #

    There are some example of using multiple Loops on The_Loops page in the codex.

    At risk of summarizing your initial post (but I don't completely understand it), couldn't you do the first loop for 4 posts of a specific cat and then do do a second loop for 14 posts of all cats -- use a variable to ignore the first 4 in that second loop while iterating.

Topic Closed

This topic has been closed to new replies.

About this Topic