This was done to restrict the effect of those filters to this one query between both calls.
There are probably other instances of WP_Query
during page load, and you don’t want to change their results.
Imagine what happens when you do not remove the filter: All later new WP_Query();
calls would be restricted to a certain date period. All posts from an author, all pages, custom post types … that would really hurt.
You don’t even need the second call, you can remove the filter from the first callback:
function filter_where( $where="" )
{
remove_filter( current_filter(), __FUNCTION__ );
// posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
Related Posts:
- Check for featured image in WP_Query
- How do I Make a Theme “plugin-ready”?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
- WP_Query returns no results
- Finding posts containing matching array elements in a meta field usign WP_Query
- Elementor custom Query with ACF fields to show matching woocommerce products custom fields
- WordPress custom taxonomy check box to dropdown
- Redirect to another page using contact form 7? [closed]
- 400 Bad Request, in wordpress theme development, wp_ajax
- Adjust query on single
- WP_Query order posts by category
- Override category archive page title (not the head title)
- Post Pagination does not working on WP-Query
- Caption Shortcode: what filter to change the image size?
- WordPress permalink setting
- post_results filter confused by pagination in sidebar and main section
- append code after the_content not working
- Best Way to Inventory the Media Library of a 200+ Multisite Installation?
- ajaxurl not defined on front end
- Where to store PHP files created by plugin / themes
- How to add multiple custom URL variables?
- Is there widely accepted phpDoc syntax for documenting which hook calls a function?
- Getting wrong relationship value in $args in wp_Query?
- Why Does get_posts() Return an Empty Set?
- How to Add a .js file Only in one specific Page Dynamically to Head
- Actions or filters fired when data is saved in a custom table
- How to get all images and their thumbnails from wp media library
- Conditional add_filter?
- Add new user and add meta at once
- How to create a dynamic page based on form data with a plugin?
- Calling apply_filters on non-documented hooks
- How to allow Unfiltered HTML in a wordpress multisite install
- Handling form request from plugin file
- Is there a way to verified if an add_filter is already applied?
- Error : “Updating failed: The response is not a valid JSON response” with custom shortcode
- What’s the better way to add an inline script?
- Metabox Not Showing on Custom Post Type But On Pages and Post
- multiple functions with same filter
- Woocommerce – Hide a Column in Cart Table
- Backslashes being stripped from CSS
- How to get orders with used coupon in WooCommerce
- How to determine if the current file is loaded in a plugin or in a theme?
- Finding the paragraphs in content
- How to avoid loading same script twice?
- Can I individually style items in the backend widget list?
- Should action callbacks start with a verb?
- Create a custom display order in the main menu
- How to Create Custom HTML Tag on Editor in `Text(HTML)` mode
- Namespaced action and filter tags
- Two functions utilizing registration_errors filter
- Beginner advice
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- How to filter users list on user_status field with get_users()
- Can Page Templates be Applied to Archive and Post Templates?
- Is there some way to provide the user a list of existing content in a CPT
- Change the look and feel of admin pages
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- What is the proper method of using global $post?
- Search and Filter
- How to change title tag at page after loaded post?
- Selectively update themes in WordPress multisite
- Remove an action by extending class and replacing it
- Getting a WordPress Debug Strategy
- Store custom meta box data as serialized array
- Conditional Generation of Image Sizes using add_image_size
- How remove trashed WooCommerce orders from wc_get_orders() result?
- WP Still Generating 150×150 Thumbnail Size Even After Un-Setting Small Size in Functions.php
- Does WordPress default CSS have Grids?
- How to resize WordPress images on upload to specific height and width without cropping it
- Get post thumbnail in WP_Query
- Toolbar Hidden in a Virtual Page
- How do i remove the title from a specific page
- Is there an action_filter hook to add content before the post title?
- Adding tables to dashboard pages programmatically?
- Why does website stretch and white space on load? [duplicate]
- Pass custom props to
- Include external po file for 3th party plugin to theme
- How to make premium plugin? I want to limit it until verification
- Multiple dynamic Tax Query – pass taxonomy argument from array
- How to hide/remvoe unnecessary field/section in post edit section ( Dashboard )
- WordPress Reset password Strength set to medium
- redirect_to how to make it simply work with get parameter or similar?
- Change Front page displays settings conditionally when user is online
- Determine if the current page, is being edited
- Is it possible to modify an Elated plugin portfolio-list template in such a way that it will not conflict with future plugin updates?
- WP Query Relations / Compare
- Woocommerce Custom Checkout
- Looping single post in a theme
- Custom theme and plugin updating
- Adding class to the parent of current-post-ancestor / current-menu-parent / current-post-parent
- problem with blank page
- Can’t get query string in ajax call
- grouping my widgets wordpress
- If I want to create new taxonomies (e.g. Project / Documents / Etc…) is it better to create them in the theme’s functions.php or within a plugin? [duplicate]
- How to add something after a function
- how many rupee or dollar charge to client to make theme [closed]
- How react js and other Javascript Technologies works on WordPress plugin?
- Do Not Back Up? Is there any accepted way to tell backup and clone plugins to skip a certain file? [closed]