Forums

[resolved] exclude recent posts in a certain category (6 posts)

  1. adria
    Member
    Posted 1 year ago #

    Hi, I have a loop that shows all recent posts, excluding one category like so:

    `numberposts=-1&cat=-9129&orderby=post_date&showposts=10

    What I would ideally like, is to only exclude the 4 most recent posts in that category (id 9129), but include the rest.

    Any help?

  2. MichaelH
    Volunteer
    Posted 1 year ago #

    What about using the offset argument?

    See query_posts()

  3. adriamooney
    Member
    Posted 1 year ago #

    The offset is definitely useful, but I don't quite how to do exactly what I want with it: Show ALL categories EXCEPT (offset 4) the most recent posts in a certain category only. If I do:

    numberposts=-1&cat=9129&offset=4&orderby=post_date&showposts=10

    It offsets the most recent 4 posts in category 9129, but doesn't show posts in all the other categories. If I just did:

    numberposts=-1&offset=4&orderby=post_date&showposts=10 It would exclude the most recent 4 posts regardless of category, which is also not what I want.

    I don't know how else I could use these parameters to achieve what I want.

  4. MichaelH
    Volunteer
    Posted 1 year ago #

    Okay, I understand what you want to do, but you can't get there with a single query_posts. You'd have to do 2 different queries, one to 4 posts from category 9129 that you want to offset, then using those post IDs construct a 2nd query with post__not_in.

  5. adria
    Member
    Posted 1 year ago #

    thanks, this got me what I needed. I just made two queries:

    numberposts=-1&cat=9129&offset=4&orderby=post_date&showposts=4

    and

    numberposts=-1&cat=-9129&orderby=post_date&showposts=6

    The first one gets that category I wanted, except the 4 most recent.
    The second one gets the rest of the categories, excluding the category that I got above. Thanks for your help!

  6. jamesmoriarty
    Member
    Posted 1 year ago #

    Hi Adria,
    Any chance you could show how exactly you made these two queries?
    I have exactly the same problem as yourself.
    Thanks
    James

Topic Closed

This topic has been closed to new replies.

About this Topic