On this page
WP_Taxonomy::add_rewrite_rules()
Adds the necessary rewrite rules for the taxonomy.
Source
File: wp-includes/class-wp-taxonomy.php. View all references
public function add_rewrite_rules() {
/* @var WP $wp */
global $wp;
// Non-publicly queryable taxonomies should not register query vars, except in the admin.
if ( false !== $this->query_var && $wp ) {
$wp->add_query_var( $this->query_var );
}
if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
if ( $this->hierarchical && $this->rewrite['hierarchical'] ) {
$tag = '(.+?)';
} else {
$tag = '([^/]+)';
}
add_rewrite_tag( "%$this->name%", $tag, $this->query_var ? "{$this->query_var}=" : "taxonomy=$this->name&term=" );
add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $this->rewrite );
}
}
Related
Uses
| Uses | Description |
|---|---|
| WP::add_query_var() wp-includes/class-wp.php | Adds a query variable to the list of public query variables. |
| add_rewrite_tag() wp-includes/rewrite.php | Adds a new rewrite tag (like %postname%). |
| add_permastruct() wp-includes/rewrite.php | Adds a permalink structure. |
| is_admin() wp-includes/load.php | Determines whether the current request is for an administrative interface page. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_taxonomy/add_rewrite_rules