Support » Fixing WordPress » does this filter code look correct

  • 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?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘does this filter code look correct’ is closed to new replies.