Adds the necessary rewrite rules for the post type.
Source
add_post_type_support( $this->name, 'autosave' );
}
} elseif ( false !== $this->supports ) {
// Add default features.
add_post_type_support( $this->name, array( 'title', 'editor', 'autosave' ) );
}
}
/**
* Adds the necessary rewrite rules for the post type.
*
* @since 4.6.0
*
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @global WP $wp Current WordPress environment instance.
*/
public function add_rewrite_rules() {
global $wp_rewrite, $wp;
if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) {
$wp->add_query_var( $this->query_var );
}
if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) {
if ( $this->hierarchical ) {
add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" );
} else {
add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" );
}
if ( $this->has_archive ) {
$archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive;
if ( $this->rewrite['with_front'] ) {
$archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
} else {
$archive_slug = $wp_rewrite->root . $archive_slug;
}
Changelog
Version | Description |
---|---|
4.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.