Function: get_site_by_path

get_site_by_path( string $domain, string $path, integer | null $segments )

Retrieves the closest matching site object by its domain and path.

This will not necessarily return an exact match for a domain and path. Instead, it breaks the domain and path into pieces that are then used to match the closest possibility from a query.

The intent of this method is to match a site object during bootstrap for a requested site address

Parameters

Name Type(s) Default Value Description
$domain string

Domain to check.

$path string

Path to check.

$segments integer | null null

Path segments to use. Defaults to null, or the full path.

Returns

WP_Site | false

Site object if successful. False when no site is found.

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.