wp_sitemaps_posts_pre_url_list
云策文档标注
概述
wp_sitemaps_posts_pre_url_list 是一个 WordPress 过滤器钩子,用于在生成文章 URL 列表之前进行干预。通过返回非空值,可以短路默认的生成过程,直接使用自定义的 URL 列表。
关键要点
- 这是一个过滤器钩子,允许在生成文章类型站点地图的 URL 列表前修改或替换数据。
- 返回非空值(如数组)将跳过默认生成逻辑,直接使用返回的值作为 URL 列表。
- 钩子接受三个参数:$url_list(URL 列表,默认为 null)、$post_type(文章类型名称)和 $page_num(结果页码)。
- 在 WordPress 5.5.0 版本中引入,主要用于 WP_Sitemaps_Posts::get_url_list() 方法。
代码示例
$url_list = apply_filters(
'wp_sitemaps_posts_pre_url_list',
null,
$post_type,
$page_num
);
原文内容
Filters the posts URL list before it is generated.
Description
Returning a non-null value will effectively short-circuit the generation, returning that value instead.
Parameters
$url_listarray[]|null-
The URL list. Default null.
$post_typestring-
Post type name.
$page_numint-
Page of results.
Source
$url_list = apply_filters(
'wp_sitemaps_posts_pre_url_list',
null,
$post_type,
$page_num
);
Changelog
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |