WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] Using a Date Range (4 posts)

  1. Joe Siegler
    Member
    Posted 2 years ago #

    http://www.rangerfans.com/wordpress/schedule/2011schedule/

    Look at that. It's a huge list of posts comprising a whole baseball season recaps. Is it possible to set up something where I am shown just posts for a specific date range?

    What I envisioned was something like this..

    April 2011
    
    [display-posts category="2011 Game Recaps" posts_per_page="-1" include_date="true" order="ASC" wrapper="ul" date="040111-043011"]
    
    May 2011
    
    [display-posts category="2011 Game Recaps" posts_per_page="-1" include_date="true" order="ASC" wrapper="ul" date="050111-053111"]

    etc.....

    Can that be done? Or am I just with just one long list there? Tkx.

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. Joe Siegler
    Member
    Posted 2 years ago #

    Also, I looked under "Further Customizations" on this page:

    http://www.billerickson.net/shortcode-to-display-posts/

    It says it has an example showing this, but there doesn't appear to be anything on the page.

  3. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    Sorry for the broken examples on that post, I've updated it.

    As of right now there's no easy way to query posts based on a date range. There's a few examples using the posts_where filter on the WP_Query Codex page.

    In WP 3.4 or 3.5 we should have improved date arguments for WP_Query.

    The way I would approach this now would be to store the post date as a UNIX timestamp in postmeta, then do queries based on it.

    Create a metabox using this CMB library that uses the 'text_date_timestamp' field, which stores the date as a UNIX timestamp.

    OR

    Write a function that automatically creates this field when you publish a post. Here's an example of something similar I wrote for converting Gravity Forms submsisions dates into unix timestamps: http://www.billerickson.net/code/gravity-forms-unix-timestamp/

    THEN

    Add two fields to your shortcode, like [display-posts start_date="04-11-11" end_date="04-30-11"]. Write an output filter that grabs these values, converts them to unix timestamps, then do a query based on them. Something like this: http://www.billerickson.net/code/event-query/

    As you can see, this is definitely not a simple addition.

  4. Joe Siegler
    Member
    Posted 2 years ago #

    Yeah, I was afraid of that. Was looking for something quick. I could probably muddle through it if I spent a ton of time, but I don't have time. I'll probably just have to go with the big list for now and adapt it later on when I have time to mess with it.

    Tkx for looking.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic