Add Filter not working with get_posts

According with WordPress documentation, the post_where filter will not affect to the query generated by the get_posts() function. See also the default usage of get_posts() where you can see the argument suppress_filters set to true by deafult. In order to run post_where filter in the query generated by get_posts() function you have to set suppress_filters argument to false:

get_posts( array( 'suppress_filters' => FALSE ) );

So, you code could be something like:

$countposts = count(get_posts(array(
                   'suppress_filters' => false,
                   'post_parent       => $id,
                   'post_type'        => 'page',
                   'post_status'      => 'publish',
                   'numberposts'      => $number,
                   'exclude'          => $exclude,
                   'orderby'          => $orderby
             )));

Also, you have a lot of variables not initializaed like, $id, $number, $exclude, $orderby or $filter_year.