I’d say it’s perfectly fine to do it the way you’re doing it now, that is
function my_the_posts($posts, $query = false) {
if( is_search() ){
// do your thing here
}
return $posts;
}
add_filter( 'the_posts', 'my_the_posts' );
Don’t worry about those excerpts in the footer, even though they may be part of the search page (which the footer will be, obviously), they’re part of a different query and so will not pass the is_search()
test.
Related Posts:
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- Schedule WordPress Auto-Updates to only run during business hours
- Preventing a plugin from updating
- How To Determine If A Filter Is Called In A Sidebar/Widget Context?
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- Filter Hook on plugin update
- WordPress Hook that will run when media file deleted
- Disallow a user to post in certain categories
- Generic plugin (de)activation hook?
- Which hook should be used to validate custom form fields on the login form?
- Hook (upgrader_process_complete) running moment
- Adding a form at the end of the content
- How can I add a custom meta value on file upload?
- Adding dynamic section to WordPress
- How can I filter blog name?
- why does the add_action(‘the_content’) overwrite my page
- Fatal error: Class not found in
- Showing Notifications While Activating Plugin
- Is it possible to remove this action? (as it’s added just before it’s called)
- Woocommerce Shipping module available only for type of products [closed]
- WordPress Plugin Boilerplate – add_action hook in static “activate” function
- Put code into body tags near top, using a plugin
- Hook before & after plugin / core update
- publish_post plugin hook doesn’t always pass $post->post_content
- get_plugins() doesn’t work after plugins_loaded
- add_action in functions.php, do_action in plugin?
- add action for displaying posts using a shortcode
- Randomize attachment IDs
- Are there hooks for WordPress updates?
- Pass info from functions.php to plugin
- Plugin activation hook in an abstract class
- Remove rewrite rules generated by plugin during deactivation
- Change permalink structure hidden button edit
- WordPress filter that hook after each action/filter hook
- When to use action hooks and plugins
- Is there an earlier hook than login_head or login_enqueue_scripts?
- Gravity Forms plugin: How to use “gform_editor_js” action hook? [closed]
- Inserting above the comment template
- Insert new user with form submit ‘init’ hook
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- Map a custom id to wordpress post id
- Calling plugin function inside custom plugin for onclick event
- get current date + 90 days and checking every day
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- Hook into existing tinyMCE button
- How to get post ID with hooks publish_post, new_to_publish, etc
- edit_user_profile and show_user_profile are not firing inside a class
- Add sub menu page in your plugin
- how to change automatic placing of social plugins below content?
- the_post hook is not firing for me
- Deactivate JS Script in Plugin Shortcode
- Create a post builder skin in a plugin
- Plugin Development – Functions or Hooks?
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Hook for page Request?
- Adding Plugin Assets to Header
- Add item to the woocommerce dashboard menu from a plugin
- How to use the pre_option filter before a plugin loads?
- What are admin hooks
- How do I add $_SESSION[”] to my wordpress page?
- How to use filter to disable adding a product to wishlist?
- WordPress: Add custom add_filter for custom functions
- How to remove a class function from a plugin by using remove_action()?
- profile_update hook doesn’t works inside a class
- Function added to hook “new_to_publish” not executing – custom plugin
- Plugin: Hooking up classes that have their own hooks
- Hook for altering the content of all wp mails
- How to deactivate my plugin upon deactivation of NextGen
- Hook for plugin to insert into entry-meta
- Change Dashboard URL from wp-admin to wp-admin/index.php
- Use a hook or filter, or overwrite this Gamipress function?
- Hook from plugin doesn’t fire up from external PHP script
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Callback hooked to post_updated firing on new posts as well
- Randomize post (and page) IDs on generation
- save_post hook partly firing in update post
- My plugin runs on every single WordPress page, but I want it to run only on activation
- The function called on the wp head hook becomes null
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Show post object of any page in frontend
- Use action, filter, or hook to append HTML to WordPress plugin function
- Passing function into add_action always returns the first argument
- Hook to display element as product on category page
- Is it possible to disable a theme programmatically?
- Hook on widget context plugin to add custom context for widget
- plugin not hooking to my custom hook
- wp_login_form() ignoring login_form action hook
- Modify a plugin’s content
- How should I use a plugin function as a hook?
- Plugin hook breaks new WP 4.0 media library grid view?
- Variable scope in plugin outside loop [closed]
- Checking url from plugin [duplicate]
- User register hook can’t access form request
- WordPress Hooks : Where to place callbacks that repetitively yield the same effect?
- How to Add Extra Text In WordPress Title Before Post Publish
- Suitable hook when creating, updating and deleting posts programmatically
- Change social icon in twenty twenty three theme
- is_user_logged_in() undefined at shutdown in plugin context