Support » Everything else WordPress » Query posts for days since last Wednesday

  • I have a publication that goes out on Wednesdays but I have updates throughout the week. I’m using wordpress to post updates only and want to setup a query that displays all update posts since the last publication (each Wednesay).

    I have not been able to figure out how to achieve this with the query_posts parameters or the php calendar functions.

    Any help would be greatly appreciated.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    There is no way to query for posts since a particular date. WordPress does not work that way.

    WordPress queries based on a set of parameters, none of those parameters is “since”. You can get all the posts for a particular day, all for a month, all for a year, all for any given week, but there’s no way to query for a range of dates. Instead, you have to get some number of posts and then eliminate the ones you don’t want.

    Like, I could get the posts for this month and then ignore all the ones that happened before last Wednesday. That’s possible. But I can’t give you a query_posts call to just give you those posts in the first place.

    I have considered similar workarounds but lets say today is the 2nd of some month and the previous Wednesday was the 29th of last month. With that method I’d be missing posts from the 29th, 30th and 31st of last month.

    I am trying to figure out a way to use the week number parameter of the gmstrftime() function to try and query posts that match the same week.

    If I can’t accomplish that I may try what I did on another blog where I would just subtract days from the current day variable and check to see if there are any posts for that day. The problem with that is that I can’t change the number of days I go back very easily as well as coming up against the issue I stated in the post above this one.

    I am actually very curious how the syntax would look for what you mentioned above.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Well, date('W') will give you the current week. Problem is that you also need to specify the year. Fortunately, date('o') will give you the year *and* account for the week surrounding the yearends correctly.

    So something like this would give you all posts from this week:


    Hmm, I don’t quite follow how that works. Query_posts accepts ‘w’ as a parameter?

    If that works that would be exactly what I need! I tried the code and its not working for me.

    Its working! Now I just need to figure out how to adjust how it counts the beginning of the week from Monday to Wednesday. I tried adjusting it in wordpress settings but that didn’t have an effect on my page.

    I still don’t understand how the query accepted ‘w’ since I thought query_posts() only accepted these:
    hour= | minute= | second= | day= | monthnum= | year=
    Are there any other time parameters that it accepts?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Query posts for days since last Wednesday’ is closed to new replies.