Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use found_sites_query filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
April 7, 2023
5 minutes read

found_sites_query filter

Alright, let’s dive into the world of WordPress hooks! Today, we’re talking about the found_sites_query filter. This little gem helps you tweak the query used to retrieve the count of found sites. To start with this hook, you’ve got to register it using add_filter. You can drop this code into the functions.php file of your active theme or, better yet, create a custom WordPress Plugin. This way, you’re all set and won’t face any hiccups when your theme updates in the future.

Here’s a quick tip: if you ever need to undo a registered hook, give remove_filter a shot to clear out the found_sites_query filter.

Live Example 1: Basic Usage

Let’s see a basic example of using the found_sites_query hook.

    function weplugins_modify_found_sites_query_defaults($found_sites_query, $site_query) { 
        // Update the $found_sites_query variable according to your website requirements and return this variable.
        return $found_sites_query; 
    }
    // add the filter
    add_filter("found_sites_query", "weplugins_modify_found_sites_query_defaults", 10, 2);
    

Live Example 2: Removing a Hook

To remove a hook callback, use the example below.

    remove_filter("found_sites_query", "weplugins_modify_found_sites_query_defaults", 10, 2);
    

Please ensure you provide the same callback function name, priority, and number of arguments while removing the hook callback.

Live Example 3: Advanced Customization

Here’s how you can modify the found_sites_query variable conditionally.

    function weplugins_advanced_modify_found_sites_query($found_sites_query, $site_query) {
        if ($site_query->is_main_query()) {
            // Make some advanced custom changes to $found_sites_query
            $found_sites_query .= " AND some_custom_condition";
        }
        return $found_sites_query;
    }
    add_filter("found_sites_query", "weplugins_advanced_modify_found_sites_query", 10, 2);
    

Access Premium WordPress Plugins

Contact Us

If you need any customization or run into issues, don’t hesitate to Contact Us. We’re here to help!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.