Retrieve a set of posts in a specified date range

Community Forums Forums General Discussion Retrieve a set of posts in a specified date range

This topic is: not resolved

This topic contains 1 reply, has 1 voice, and was last updated by  stacyvlasits 1 year, 7 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #25515

    stacyvlasits
    Participant
    Post count: 6

    I have a category called “News.”  On my “News” category page I would like to only show posts that have been made in the last 30 days.

    Here is the code I started out with:

    <code>

    remove_action(‘genesis_loop’, ‘genesis_do_loop’);
    add_action(‘genesis_loop’, ‘pm_recent_news_loop’);

    function pm_last_name_loop() {
    global $query_args;
    $args = (array(
    //????
    ));

    genesis_custom_loop( wp_parse_args($query_args, $args) );

    }
    genesis();

    </code>

    In the general WordPress API documentation it basically says that you can’t achieve filtering by date range by passing in arguments to the $query_args (which is the way that genesis_custom_loop accomplishes it. Instead, it seems that the correct way to do this is to add_filter (‘posts_where’, ‘my_where_filter’) and then define the where clause by post_date.  Ref:  http://codex.wordpress.org/Class_Reference/WP_Query#Parameters.

    However I can’t get this to work. When I attempt to implement code similar to that described in the codex I either get none of my posts or I get all of my posts.  I assume that this is because Genesis somehow works around the posts_where filter or wraps it in such a way that it doesn’t get called.

    Thoughts?

    #25895

    stacyvlasits
    Participant
    Post count: 6

    Is it bad form to /bump a post in this forum? I’m worried I may have posted this too late in the day for it to be seen.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.