钩子文档

post_rewrite_rules

💡 云策文档标注

概述

post_rewrite_rules 是一个 WordPress 过滤器,用于修改“post”文章类型的重写规则。它允许开发者自定义文章归档页面的 URL 结构。

关键要点

  • 这是一个过滤器,用于过滤“post”文章类型的重写规则数组。
  • 参数 $post_rewrite 是一个字符串数组,键为正则表达式模式,值为对应的重写规则。
  • 仅影响文章类型为“post”的内容,不适用于其他自定义文章类型。
  • 在 WP_Rewrite::rewrite_rules() 方法中被调用,用于构建重写匹配和查询。
  • 自 WordPress 1.5.0 版本引入。

代码示例

$post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite );

📄 原文内容

Filters rewrite rules used for “post” archives.

Parameters

$post_rewritestring[]
Array of rewrite rules for posts, keyed by their regex pattern.

More Information

This post will only affect content of the post type ‘posts’.

Source

$post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite );

Changelog

Version Description
1.5.0 Introduced.