Passing Additional Parameters to a Filter

While working on project an interesting problem arose, needing to pass an additional parameter to a WordPress filter. Normally filters only allow for a set number of parameters, but the particular filter needed an additional parameter that could be passed when calling the filter.

The problem was being able to run a WP_Query for a set number of days passed. This is normally accomplished with a simple filter that is applied to posts_where. The problem is the number of days would be variable, since it was being set via a widget option. To get around this using OOP and create a new class that stores the variable and that will be passed when calling the filter. While the example below is a specific solution to the problem above it can be adapted for pretty well any filter that needs another parameter that can be set when calling the filter.

About Jeremy Clark

Small town IT worker with interests in all things technological and technical. Biggest interests are in web development especially the WordPress publishing platform and the community supporting it. Currently developing and maintain the free WordPress theme Techozoic. I'm also always available for hire.
This entry was posted in Development, Featured, tech, wordpress. Bookmark the permalink.

Leave a replyLeave a Reply to Anonymous

Comments will be sent to the moderation queue.