Your code should look something like this:
class my_Widget extends WP_Widget {
...
function filter_where( $where="" ) {
...
}
function widget( $options ) {
...
add_filter( 'posts_where', array( $this, 'filter_where' ) );
$query = new WP_Query( $args );
remove_filter( 'posts_where', array( $this, 'filter_where' ) );
}
}
This will keep the function within your class, access it at a class level, and avoid any namespace issues.
Related Posts:
- Switching themes without losing widgets?
- can require “themefolder/includes/widgets.php” in “themefolder/functions.php” yet widgets.php doesn’t run
- Moving WordPress.com theme and widget settings to self-hosted site?
- Loading template files from a subfolder in my theme?
- Why are my widgets not saving when being added to a sidebar?
- Duplicate and change a Theme Widget
- Current theme broken – after server and domain migration
- How can I show more than 15 themes at a time in the admin menu?
- Changing $before_widget for certain widgets
- adding multiple sidebars on pages
- Embedded Videos (PB) – Not Available
- Hide default “Recent Comments” Widget if there are no comments yet
- Widgets menu does not appear under “Appearance” in dashboard
- Calling widget via function in themes files (hard code)
- Make it possible to pick a color theme for specific pages
- OptimizePress Theme Overriding add_filter page_template
- Inject widgets from one sidebar into another with PHP
- How to conditionally display widgetized areas in theme customizer?
- Execute filter in theme as last
- Add more widget areas to a theme
- Displaying a widget in sidebar only when no other widgets rendered?
- Style the archives/category sidebar widget via theme
- Restrict access to specific widget field based on user role
- Modifying the markup in the Tag Cloud widget?
- How to override / customize existing Widgets?
- Posts as filtered list – expandable
- Widgets not showing on sidebars
- disable default widgets in Responsive theme
- What happened to my Inactive Widgets?
- Fix warning: Missing argument
- In a specific blog, the K2 theme does not have a Text Widget
- Removing a widget via theme editor
- sidebar in 2020 theme as a widget
- How to customize a section of a widget only on certain pages or page
- Don’t prepend WordPress base url to image paths
- Changing theme folder name disrupts widgets
- Are immediately-called actions not usable in themes?
- Firebug and Chrome rendering two body tags
- No “available widgets” (wordpress 3.2.1 multisite)
- How to change background color in the Notepad++ text editor?
- How to change or add theme to Android Studio?
- WordPress frameworks and parent themes [closed]
- Opinions and recommendations on the best barebones base theme [closed]
- Remove JSON API links in header html
- Using OOP in themes
- Where can I download WordPress themes from? [closed]
- How can I allow the Editor Role to change Theme Settings?
- What are all the available parameters for query_posts?
- How can I modify the WordPress default widget output?
- Customizing a WordPress theme without changing it?
- Where can I learn to create my own theme?
- How do I turn off self-closing tags for markup in WordPress (for HTML5, or HTML4, for example)?
- how to add version of style.css in wordpress
- Does WordPress work without a theme?
- What is the role and history of the $content_width global variable?
- Adding admin-ajax.php to the frontend. Good or bad idea?
- How do I exclude plugins from getting automatically updated?
- How to move the sidebar in TwentyFifteen to the right?
- How to Link External jQuery/Javascript files with WordPress
- Installation failed: Download failed. No working transports found
- What is theme-compat?
- Override parent theme translation on child theme
- WordPress Theme activation hook?
- Can wordpress theme folder name be changed freely and nothing technically happens
- Link to specific Customizer section
- What does exactly GPL license mean for my WordPress theme?
- Am I allowed to license my WordPress theme under the aGPL
- How do I change the header image height in Twenty Seventeen?
- Starter Theme vs Parent Theme? Pros and cons
- How to change the language for the front-end only?
- W3 Total Cache, CDN and theme files [closed]
- Best way to include Bootstrap in WordPress
- How do register_sidebar() and get_sidebar() work together?
- How to set thumbnail image for a (child) theme
- Different template of products for specific category. WooCommerce
- Show different theme for admin?
- How can I version the main CSS file?
- what the best way to include images from the template’s images folder?
- Is it OK to remove theme credits from footer? [duplicate]
- Undefined offset: 0 in > […] /wp-includes/capabilities.php on line 1067
- How can I get the title attribute from get_the_post_thumbnail()?
- Dash or underscore in theme folder name?
- No “Add New” Button. How to add new theme?
- How do I add support to my theme for custom menus?
- “Unexpected error” on update requests
- How to prevent plugin, theme installation failures on WordPress?
- How do I white label my self-hosted site created by wordpress?
- Do Child-Themes automatically load the Translation from the Parent-Theme?
- Extend WordPress 3.8 Site Activity Dashboard Widget to include more comments
- When cropping a header image, retain meta data (i.e. name, description, etc.) from original image?
- Best practices for a Style/CSS based theme options page?
- How to create a new theme from scratch?
- Categorising themes by folders in backend
- How to influence the information displayed on widget inside wp-admin
- How to use media upload on theme option page?
- Should I use set_transient or update_option?
- Dynamic template serving, change theme_root using add_filter from current theme
- How to hook into unregistering a widget instance?
- What theme is good for posting code? [closed]
- WordPress 5 / Gutenberg – theme doesn’t have featured image option showing up