The get_network_by_path() WordPress PHP function retrieves the closest matching network for a domain and path.
Usage
get_network_by_path( $domain, $path, $segments = null );
Parameters
$domain
(string) – Required. Domain to check.$path
(string) – Required. Path to check.$segments
(int|null) – Optional. Path segments to use. Defaults to null, or the full path. Default: null
More information
See WordPress Developer Resources: get_network_by_path()
Examples
Retrieve network for a specific domain and path
This example retrieves the network information for the domain “example.com” and path “/blog/”. The third parameter is left as default to search the full path.
$domain = 'example.com'; $path = '/blog/'; $network = get_network_by_path($domain, $path);
Retrieve network for a domain and path using segments
This example retrieves the network information for the domain “example.com” and path “/blog/category/”. We set the $segments
parameter to 1, which means only the first segment of the path (“/blog”) will be used for the search.
$domain = 'example.com'; $path = '/blog/category/'; $segments = 1; $network = get_network_by_path($domain, $path, $segments);
Retrieve network for a domain with a subdomain
This example retrieves the network information for the subdomain “blog.example.com” and path “/”.
$domain = 'blog.example.com'; $path = '/'; $network = get_network_by_path($domain, $path);
Retrieve network for a domain with a different path
This example retrieves the network information for the domain “example.com” and path “/store/”.
$domain = 'example.com'; $path = '/store/'; $network = get_network_by_path($domain, $path);
Retrieve network using custom segments in a long path
This example retrieves the network information for the domain “example.com” and a long path “/blog/category/subcategory/”. We set the $segments
parameter to 2, which means only the first two segments of the path (“/blog/category”) will be used for the search.
$domain = 'example.com'; $path = '/blog/category/subcategory/'; $segments = 2; $network = get_network_by_path($domain, $path, $segments);