CPT
Class to handle the Custom Post Type and Taxonomies.
Namespace: WebberZone\Knowledge_Base
Since: 2.3.0
Source: includes/class-cpt.php line 22
Methods
__construct()
Constructor.
Since: 2.3.0
Line: 29
public function __construct( );
register_kb_types() static
Register taxonomies before the post type so taxonomy rewrite rules are generated first and take precedence over CPT attachment rules.
Since: 3.1.0
Line: 39
static public function register_kb_types( );
register_post_type() static
Register Knowledge Base Post Type.
Since: 2.3.0
Line: 49
static public function register_post_type( );
sanitize_slug() static
Sanitize slug while preserving slashes and optionally removing placeholders.
Since: 3.0.0
Line: 146
static public function sanitize_slug( string $slug, bool $remove_placeholders = ... ): string;
| Type | Name | Description |
|---|---|---|
string | $slug | The slug to sanitize. |
bool | $remove_placeholders | Whether to remove placeholders. Default true. |
Returns: string — Sanitized slug.
register_taxonomies() static
Register Knowledgebase Custom Taxonomies.
Since: 2.3.0
Line: 256
static public function register_taxonomies( );
filter_root_level_permalink() static
Filter KB article permalinks to remove the CPT slug when using %postname% structure.
Since: 3.0.0
Line: 336
static public function filter_root_level_permalink( $permalink, $post ): string;
| Type | Name | Description |
|---|---|---|
string | $permalink | The post’s permalink. |
\WP_Post | $post | The post object. |
Returns: string — Filtered permalink.
maybe_query_kb_article() static
Maybe query KB article if regular post isn’t found.
When using %postname% structure, WordPress will try to find a regular post first. If not found, we check if there’s a KB article with that slug.
Since: 3.0.0
Line: 358
static public function maybe_query_kb_article( $query );
| Type | Name | Description |
|---|---|---|
\WP_Query | $query | The WP_Query instance. |
add_root_level_rewrite_rules() static
Add root-level rewrite rules for KB articles when using %postname% structure.
This allows KB articles to use the same permalink structure as regular posts. Note: These rules are added but WordPress will try regular posts first, then fall back to KB articles.
Since: 3.0.0
Line: 423
static public function add_root_level_rewrite_rules( );
add_taxonomy_rewrite_rules() static
Add taxonomy rewrite rules with top priority.
This ensures taxonomy archive URLs are matched before post type attachment rules.
Since: 3.0.0
Line: 437
static public function add_taxonomy_rewrite_rules( );