Using WordPress ‘populate_network_meta()’ PHP function

The populate_network_meta() WordPress PHP function creates WordPress network meta and sets the default values.

Usage

populate_network_meta($network_id, $meta = array());

Parameters

  • $network_id (int) – Required Network ID to populate meta for.
  • $meta (array) – Optional custom meta $key => $value pairs to use. Default: array()

More information

See WordPress Developer Resources: populate_network_meta()

Examples

Populating Network Meta with Default Values

Populate network meta for network with ID 2 using default values:

populate_network_meta(2);

Populating Network Meta with Custom Values

Populate network meta for network with ID 3 and custom meta values:

$custom_meta = array(
    'custom_key_1' => 'custom_value_1',
    'custom_key_2' => 'custom_value_2'
);
populate_network_meta(3, $custom_meta);

Populating Network Meta with a Mix of Default and Custom Values

Populate network meta for network with ID 4, overwriting default values with custom values:

$custom_meta = array(
    'site_name' => 'My Custom Network'
);
populate_network_meta(4, $custom_meta);

Populating Network Meta for a Newly Created Network

After creating a new network, populate its network meta:

$new_network_id = 5;
populate_network_meta($new_network_id);

Populating Network Meta for Multiple Networks

Populate network meta for multiple networks using a loop:

$network_ids = array(6, 7, 8);

foreach ($network_ids as $network_id) {
    populate_network_meta($network_id);
}