Support » Plugins » Limiting a loop to an amount of days

  • I’m trying to use this filter

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

    to limit the amount of days for posts in different loops but Im confused on how to use it on multiple different loops on one page. I add it before a loop and then remove the filter at the end of the loop but when I try to place the code before another loop and set a different amount I get an error saying “Cannot redeclare filter_where() (previously declared in “. How can I use it in multiple occurrences?

  • The topic ‘Limiting a loop to an amount of days’ is closed to new replies.