WordPress函数文档flush_rewrite_rules()

更新伪静态规则 描述 Remove rewrite rules and then recreate rewri…

更新伪静态规则

描述

Remove rewrite rules and then recreate rewrite rules.

This function is useful when used with custom post types as it allows for automatic flushing of the WordPress rewrite rules (usually needs to be done manually for new custom post types). However, this is an expensive operation so it should only be used when absolutely necessary. See Usage section for more details.

用法

Important:

  • Flushing the rewrite rules is an expensive operation, there are tutorials and examples that suggest executing it on the ‘init’ hook. This is bad practice.
  • Flush rules only on activation or deactivation, or when you know that the rewrite rules need to be changed. Don’t do it on any hook that will triggered on a routine basis. More detail information in the comments on WP Engineer’s post: Custom Post Type and Permalink
  • Make sure custom post types and taxonomies are properly registered before flushing rewrite rules, especially during plugin activation: Activation Checklist for WordPress Plugin Developers

<?php flush_rewrite_rules$hard ); ?>

参数

$hard

(boolean) (可选) Whether to update .htaccess (hard flush) or just update rewrite_rules transient (soft flush).

默认值: true (hard flush)

示例

This is how you would flush rewrite rules when a plugin is activated or deactivated:

This is how you would flush rules on theme activation:

If you’re developing a theme, while building it you can use this snippet of code that will flush rewrite rules when the file containing it is changed, or every 48 hours:

历史

添加于 版本: 3.0

源文件

flush_rewrite_rules() 函数的代码位于 wp-includes/rewrite.php

  • 原文:http://codex.wordpress.org/Function_Reference/flush_rewrite_rules
类别:WordPress函数文档

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT