返回介绍

wp_get_sites()

发布于 2017-09-11 12:09:04 字数 6146 浏览 833 评论 0 收藏 0

Warning: This function has been deprecated. Use get_sites() instead.

wp_get_sites( array $args = array() )

Return an array of sites for a network or networks.


description


参数

$args

(array) (Optional) Array of default arguments. Optional.

  • 'network_id'
    (int|array) A network ID or array of network IDs. Set to null to retrieve sites from all networks. Defaults to current network ID.
  • 'public'
    (int) Retrieve public or non-public sites. Default null, for any.
  • 'archived'
    (int) Retrieve archived or non-archived sites. Default null, for any.
  • 'mature'
    (int) Retrieve mature or non-mature sites. Default null, for any.
  • 'spam'
    (int) Retrieve spam or non-spam sites. Default null, for any.
  • 'deleted'
    (int) Retrieve deleted or non-deleted sites. Default null, for any.
  • 'limit'
    (int) Number of sites to limit the query to. Default 100.
  • 'offset'
    (int) Exclude the first x sites. Used in combination with the $limit parameter. Default 0.

Default value: array()


返回值

(array) An empty array if the install is considered "large" via wp_is_large_network(). Otherwise, an associative array of site data arrays, each containing the site (network) ID, blog ID, site domain and path, dates registered and modified, and the language ID. Also, boolean values for whether the site is public, archived, mature, spam, and/or deleted.


源代码

File: wp-includes/ms-deprecated.php

function wp_get_sites( $args = array() ) {
	global $wpdb;

	_deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' );

	if ( wp_is_large_network() )
		return array();

	$defaults = array(
		'network_id' => $wpdb->siteid,
		'public'     => null,
		'archived'   => null,
		'mature'     => null,
		'spam'       => null,
		'deleted'    => null,
		'limit'      => 100,
		'offset'     => 0,
	);

	$args = wp_parse_args( $args, $defaults );

	// Backwards compatibility
	if( is_array( $args['network_id'] ) ){
		$args['network__in'] = $args['network_id'];
		$args['network_id'] = null;
	}

	if( is_numeric( $args['limit'] ) ){
		$args['number'] = $args['limit'];
		$args['limit'] = null;
	} elseif ( ! $args['limit'] ) {
		$args['number'] = 0;
		$args['limit'] = null;
	}

	// Make sure count is disabled.
	$args['count'] = false;

	$_sites  = get_sites( $args );

	$results = array();

	foreach ( $_sites as $_site ) {
		$_site = get_site( $_site );
		$results[] = $_site->to_array();
	}

	return $results;
}

更新日志

Versiondescription
4.6.0This function has been deprecated. Use get_sites() instead.
3.7.0Introduced.

More Information

If wp_is_large_network() returns TRUE, wp_get_sites() will return an empty array. By default wp_is_large_network() returns TRUE if there are 10,000 or more sites in your network. This can be filtered using the wp_is_large_network filter.

Each site’s array is composed entirely of string values, even for numeric values. This means that == or !=, not === or !==, should be used to compare [blog_id] to get_current_blog_id(), which returns an integer value.


相关函数

Uses

  • wp-includes/ms-blogs.php: get_sites()
  • wp-includes/ms-blogs.php: get_site()
  • wp-includes/functions.php: _deprecated_function()
  • wp-includes/functions.php: wp_parse_args()
  • wp-includes/ms-functions.php: wp_is_large_network()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    if you specify null to the ‘network_id’ then all site infomation in the network are returned.

    
    <?php 
    $args = array(
        'network_id' => null,
        'public'     => null,
        'archived'   => null,
        'mature'     => null,
        'spam'       => null,
        'deleted'    => null,
        'limit'      => 100,
        'offset'     => 0,
    ); 
    $array = wp_get_sites( $args );
    print_r ($array);
    ?>
    

    Example of the array returned:

    
    Array(
        [0] => Array(
            [blog_id] => 1
            [site_id] => 1
            [domain] => example.com
            [path] => /
            [registered] => 2013-11-08 17:56:46
            [last_updated] => 2013-11-08 18:57:19
            [public] => 1
            [archived] => 0
            [mature] => 0
            [spam] => 0
            [deleted] => 0
            [lang_id] => 0
        )
    
        [1] => Array(
            [blog_id] => 2
            [site_id] => 1
            [domain] => example.com
            [path] => /examplesubsite/
            [registered] => 2013-11-08 18:07:22
            [last_updated] => 2013-11-08 18:13:40
            [public] => 1
            [archived] => 0
            [mature] => 0
            [spam] => 0
            [deleted] => 0
            [lang_id] => 0
        )
    )
    

    If you specified ‘1’ to the ‘network_id’ then the array that include only the first element must be returned.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文