tags:

views:

19

answers:

1

Hey all,

I was wondering how I can get the last three posts before (and after) a certain date.

I was looking at query_post but I can't figure it out.

I'm looking to do this in functions.php. Ideally, it would return just basic home page stuff.. title, first image, num_comments, etc. I don't need to query the whole article.

EDIT: I would also like this all done in one function.. there are explanations out there on how to add a filter function.. which I don't want to do. If the functionality could be simply placed in add_filter(...) that would be fine.

Any help would be very much appreciated!

Matt

A: 

Got'er. Uses AJAX. Thank you for being a baller PHP (inner functions).

function ajax_get_next_posts($wp) {
    if(!$_POST['date']) return 'error';

    function filter_where($where = '') {
            $where .= " AND post_date <= '{$_POST['date']}'";
        return $where;
    }
    add_filter('posts_where', 'filter_where');
    $posts = query_posts('posts_per_page=3');
    print_r($posts);
}
Matt
You should probably escape your $_POSTed variable. Try:global $wpdb;$where = $wpdb->prepare( " AND post_date <= %s", $_POST['date'] );return $where;
nickohrn