函数文档

get_last_updated()

💡 云策文档标注

概述

get_last_updated() 函数用于获取最近更新的博客列表,基于 WordPress 多站点环境中的数据库查询。它接受偏移量和数量参数以支持分页,并返回符合条件的博客数组。

关键要点

  • 函数返回一个数组,包含最近更新的博客信息,如 blog_id、domain 和 path。
  • 参数 $deprecated 已弃用且未使用,$start 用于偏移查询(默认 0),$quantity 控制返回博客数量(默认 40)。
  • 查询条件包括站点 ID 匹配、公开状态、非归档、非成熟、非垃圾、非删除,且 last_updated 不为空值。
  • 使用 wpdb::prepare() 进行 SQL 查询安全处理,并通过 wpdb::get_results() 获取结果。

代码示例

function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
	global $wpdb;

	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, 'MU' ); // Never used.
	}

	return $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", get_current_network_id(), $start, $quantity ), ARRAY_A );
}

注意事项

此函数仅适用于 WordPress 多站点环境,且 $deprecated 参数在 MU(3.0.0)版本后已标记为弃用,实际使用中应忽略。


📄 原文内容

Gets a list of most recently updated blogs.

Parameters

$deprecatedmixedrequired
Not used.
$startintoptional
Number of blogs to offset the query. Used to build LIMIT clause.
Can be used for pagination. Default 0.
$quantityintoptional
The maximum number of blogs to retrieve.

Default:40

Return

array The list of blogs.

Source

function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
	global $wpdb;

	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, 'MU' ); // Never used.
	}

	return $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", get_current_network_id(), $start, $quantity ), ARRAY_A );
}

Changelog

Version Description
MU (3.0.0) Introduced.