I'm adding a filter for a WordPress query in a widget. I'm adding as following:
function filter_where( $where = '' ) {
}
add_filter( 'posts_where', 'filter_where' );
$query = new WP_Query( $args );
remove_filter( 'posts_where', 'filter_where' );
It works fine, but if I use the same widget more than 1 times then I get the fatal error that the same filter cannot be re-declared. How can I use the filter so that the same widget can be used multiple times?
This is the exact error I get:
Fatal error: Cannot redeclare filter_where() (previously declared in xxx.php:70)
Thanks.
if ( !function_exists('filter_where')) {}
wrapper would do the trick.enam_filter_where
in both your add/remove filter statements, and the function definition - still get the error? A plugin you have may have the same function name.