函数文档

start_wp()

💡 云策文档标注

概述

start_wp() 是一个已弃用的 WordPress 函数,用于设置 WordPress Loop,但建议使用 The Loop 替代。它通过操作全局 $wp_query 对象来推进查询迭代器并设置全局文章数据。

关键要点

  • start_wp() 自 WordPress 1.5.0 起已弃用,推荐使用 The Loop 进行替代。
  • 函数内部调用 $wp_query->next_post() 来设置下一篇文章并迭代当前文章索引。
  • 使用 setup_postdata() 和 get_post() 来设置全局文章数据。
  • 相关函数包括 WP_Query::next_post()、setup_postdata()、__()、_deprecated_function() 和 get_post()。

注意事项

由于此函数已弃用,开发者应避免在新代码中使用,转而采用标准的 The Loop 结构以确保兼容性和最佳实践。


📄 原文内容

Sets up the WordPress Loop.

Description

Use The Loop instead.

Source

function start_wp() {
	global $wp_query;

	_deprecated_function( __FUNCTION__, '1.5.0', __('new WordPress Loop') );

	// Since the old style loop is being used, advance the query iterator here.
	$wp_query->next_post();

	setup_postdata( get_post() );
}

Changelog

Version Description
1.5.0 Deprecated.
1.0.1 Introduced.