函数文档

get_post_format_slugs()

💡 云策文档标注

概述

get_post_format_slugs() 函数用于检索文章格式的 slugs 数组,返回的数组以 slugs 同时作为键和值。

关键要点

  • 函数返回一个字符串数组,包含所有文章格式的 slugs。
  • 内部实现基于 get_post_format_strings() 函数,通过 array_combine 生成键值相同的数组。
  • 该函数自 WordPress 3.1.0 版本引入,常用于主题和插件开发中处理文章格式。

相关用途

  • 在 build_query_vars_from_query_block() 中用于构建 WP_Query 参数。
  • 在 create_initial_theme_features() 中初始化主题功能。
  • 在 WP_REST_Posts_Controller 的方法中用于 JSON Schema 和查询参数。
  • 与 add_theme_support() 和 set_post_format() 等函数协同工作。

📄 原文内容

Retrieves the array of post format slugs.

Return

string[] The array of post format slugs as both keys and values.

Source

function get_post_format_slugs() {
	$slugs = array_keys( get_post_format_strings() );
	return array_combine( $slugs, $slugs );
}

Changelog

Version Description
3.1.0 Introduced.