WordPress.org

Ready to get started?Download WordPress

Forums

does this filter code look correct (2 posts)

  1. shamai
    Member
    Posted 2 years ago #

    I wanted to create a second loop that shows 1 post and it has to be less than 10 days old.
    so i read up on it and I put this in my functions.php:

    function filter_where($where = '') {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-10 days')) . "'"; 
    
        return $where;
    }

    then in the loop I have this:

    add_filter('posts_where', 'filter_where');
     $featured= new wp_query();
    
     $featured -> query('meta_key=featured&posts_per_page=1');
     remove_filter('posts_where', 'filter_where');
     while ($featured -> have_posts()): $featured->the_post();
       $wp_query-> in_the_loop = true;
    					?> ....

    is the line
    remove_filter('posts_where', 'filter_where');
    necessary?
    it seems to work without it and the rest of my posts are showing normally using the default loop.

    so what is that line for?

    and do I need to reset the query?

  2. Matthew Gedeon
    Member
    Posted 2 years ago #

    You might get better results by posting in the themes and templates area.
    This is what I've found, but I'm really not sure what the remove does in the context of the above code.

Topic Closed

This topic has been closed to new replies.

About this Topic