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?
- Creating a Link Text like Submit Button in Admin Page
- Beginner advice
- Change the ‘published on’ text?
- Is there a Filter that I can use to filter the tags before they are inserted in to the database?
- WordPress is automatically linking plain text email addresses
- How to render a time-of-day string like ’16:42′ with a site’s chosen time format?
- Are block templates incompatible with serialize_blocks?
- best practice for query string values – get_query_var always empty for my value supplied in query string
- get_current_screen() return null
- How to filter users list on user_status field with get_users()
- Slow WP_query due to nested wp_query. Need Suggestions
- Get Current Menu Location inside Nav_Walker
- Problems with: manage_${post_type}_posts_columns
- How To Change Logout Screen Title
- SQL query for custom taxonomy slugs
- Tried in different ways but sidebar not working?
- Can Page Templates be Applied to Archive and Post Templates?
- ORDER BY wp_post custom column name in wp_query
- Add code inside specific wordpress standard function
- Short code not working in boostrap modal dont no why?
- Is there a way to list all actions registered by a plugin or theme?
- Howto: Use Custom Post Types as Submenu Items in Admin
- How to create database table, add data, update and delete using wpdb via plugins?
- Check for template part, else filter content
- Is there some way to provide the user a list of existing content in a CPT
- Change the look and feel of admin pages
- Why doesn’t my simple the_title filter get applied?
- How to filter the_content() & include content from template
- Extending theme PHP class in plugin
- Adding rewrite rule dynamically
- How to access noticeOperations from withNotices
- How to hook a custom user function to a wordpress core ajax action?
- WP Gutenberg Blocks – How to limit first/root blocks
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Replace youtube embed in wordpress
- How to get boolean value from register_meta properly?
- what is the difference between these phares?
- WP_Query filters
- Form doesnt save to database
- Notice: Trying to get property ‘term_id’ of non-object
- Can’t get woocommerce_get_price_html to work [closed]
- What is the proper method of using global $post?
- How to fetch only current hour posts?
- How to get Metabox custom field to show checked if value is updated using post meta query?
- How developed with version control word press site on shared host? [closed]
- Search and Filter
- How to export post meta with images in wordpress
- Password field is empty when using wp_signon();
- WordPress pre_get_posts with combined results of two queries (OR)
- How can I replace content in the WP Admin area before an admin page is rendered?
- How to change title tag at page after loaded post?
- Following WordPress Markup Is mandatory, got awkward resultyby wordpress standard markup?
- How do I create plugin or theme using MVC pattern?
- How to limit number of number of categories displayed by categories widget
- Search: how to extend the existing search to include a custom table
- How to filter content for specific content variable
- PowerPress mobile media player
- When is the proper time to minify css and js with git workflow?
- Strange Situation When Try To Retrieve Github Gist Using wp_remote_get
- How to hide or rename “X” and “x-child” references in website source?
- How to Get Current Custom Post Type Associated Taxonomy Term
- Plugin templates vs Parent Theme
- Selectively update themes in WordPress multisite
- Using ob_get_content to get_search_form puts into infinite loop
- how to get all the child category name in a specified category name?
- Widget HTML Display Problem
- Valid filenames for add_action’s first parameter
- How do I access the menus produced by Dashboard > Appearance > Menus
- How to create a backend for a custom theme?
- wp_nonce_field displaying twice
- WordPress class, using add_action to call member function does not work
- how to invoke wordpress API from other existing PHP system
- Warning: include(): https:// wrapper is disabled in the server configuration by allow_url_include=0
- Plugin is not generating title tags on any pages or posts
- How I can use order by of the custom post title?
- Is it necessary to do validation again when retrieving data from database?
- How to Control CSS of Admin On Creating only a Specific Custom Post Type
- Can’t change the style of a submit input type? [closed]
- How to get all queries’s results after they have executed?
- Make a plugin page out of influence of the theme’s style