The found_networks_query WordPress PHP filter allows you to modify the SQL query used to retrieve the count of found networks.
Usage
add_filter('found_networks_query', 'your_custom_function', 10, 2);
function your_custom_function($found_networks_query, $network_query) {
// your custom code here
return $found_networks_query;
}
Parameters
$found_networks_query(string) – The SQL query used to retrieve the found network count. Default is ‘SELECT FOUND_ROWS()’.$network_query(WP_Network_Query) – The WP_Network_Query instance.
More information
See WordPress Developer Resources: found_networks_query
Examples
Custom network count query
To change the SQL query for retrieving the count of found networks:
add_filter('found_networks_query', 'custom_network_count_query', 10, 2);
function custom_network_count_query($found_networks_query, $network_query) {
// Change the SQL query to count networks with specific criteria
$found_networks_query = 'SELECT COUNT(*) FROM wp_networks WHERE is_active = 1';
return $found_networks_query;
}
Exclude networks based on specific criteria
To exclude specific networks from the count based on certain criteria:
add_filter('found_networks_query', 'exclude_networks_from_count', 10, 2);
function exclude_networks_from_count($found_networks_query, $network_query) {
// Exclude networks with 'test' in their path
$found_networks_query = "SELECT FOUND_ROWS() FROM wp_networks WHERE path NOT LIKE '%test%'";
return $found_networks_query;
}
Limit network count to a maximum value
To limit the count of found networks to a specific maximum value:
add_filter('found_networks_query', 'limit_network_count', 10, 2);
function limit_network_count($found_networks_query, $network_query) {
// Limit the found networks count to a maximum of 10
$found_networks_query = 'SELECT COUNT(*) FROM wp_networks LIMIT 10';
return $found_networks_query;
}
Combine multiple conditions in network count query
To combine multiple conditions in the SQL query for retrieving the count of found networks:
add_filter('found_networks_query', 'combine_conditions_network_count', 10, 2);
function combine_conditions_network_count($found_networks_query, $network_query) {
// Retrieve the count of active networks that have 'example' in their domain
$found_networks_query = "SELECT COUNT(*) FROM wp_networks WHERE is_active = 1 AND domain LIKE '%example%'";
return $found_networks_query;
}
Debugging network count query
To debug the SQL query used for retrieving the count of found networks:
add_filter('found_networks_query', 'debug_network_count_query', 10, 2);
function debug_network_count_query($found_networks_query, $network_query) {
// Output the SQL query to the error log
error_log('Network count query: ' . $found_networks_query);
return $found_networks_query;
}