Wiki

Registers a custom post type for managing a wiki/knowledge base and specific custom blocks & templates

Last modified: January 5, 2026

link Extension name

t2/wiki

The Wiki extension (t2/wiki) provides a complete knowledge base / documentation system for WordPress. It registers a custom post type for wiki articles with hierarchical topics, search functionality, and specialized blocks for navigation and discovery.

link For End Users

link What Does This Extension Do?

The Wiki extension allows you to:

link Features Available

link Post Type: Wiki Article

link Taxonomy: Topics

link Article Features

link Custom Blocks

link How to Use

  1. Enable the Extension

    • Go to WordPress Admin → T2 Settings
    • Enable the "Wiki" extension
    • Important: Also enable dependencies:
      • t2/enable-generate-anchors (for TOC support)
      • t2/table-of-contents (for TOC block)
    • Or add to your theme's t2.json:
      {
        "mu-extensions": [
          "t2/wiki",
          "t2/enable-generate-anchors",
          "t2/table-of-contents"
        ]
      }
  2. Create Topics

    • Navigate to "Wiki" → "Topics" in WordPress admin
    • Create parent topics (e.g., "Getting Started", "Advanced")
    • Create child topics under parents for nested structure
    • Topics can have descriptions and custom slugs
  3. Create Wiki Articles

    • Go to "Wiki" → "All articles"
    • Click "New article"
    • Write your article content using the block editor
    • Assign one or more topics
    • Add featured image and excerpt (optional)
    • Configure article settings in the sidebar:
      • Enable/disable Table of Contents
      • Enable/disable Topic Tree in sidebar
  4. Add Search to Your Site

    • Edit any page where you want wiki search
    • Add the Wiki Search block
    • Configure initial articles display:
      • Empty: Show search box only
      • Latest: Display recent articles
      • Manual: Choose specific articles to show
    • Customize search placeholder and styling
  5. Display Topics

    • Add the Wiki Topics block to any page
    • Choose display mode:
      • All topics
      • Manual selection of specific topics
      • Subtopics of a parent topic
    • Configure articles per topic limit
    • Show/hide article counters

link Best Practices


link For Developers

link Architecture

link File Structure

packages/extension-library/src/wiki/
├── block-library/
│   ├── wiki-search/          # Search interface block
│   │   ├── block.json
│   │   ├── block.php
│   │   ├── editor.js
│   │   ├── view.js           # Frontend search functionality
│   │   └── style.css
│   └── wiki-topics/          # Topics display block
│       ├── block.json
│       ├── block.php
│       ├── editor.js
│       └── style.css
├── inc/
│   ├── api/                  # REST API endpoints
│   ├── assets.php            # Asset enqueueing
│   ├── config.php            # Configuration helpers
│   ├── helpers.php           # Utility functions
│   ├── rest-api.php          # REST API registration
│   ├── schema.php            # Post type & taxonomy registration
│   └── templating.php        # Featured content templates
├── templates/                # PHP templates for rendering
├── src/                      # Source files (if applicable)
├── extension.json            # Extension metadata
├── extension.php             # Entry point
├── constants.js              # JS constants
├── index.js                  # Frontend JS initialization
├── view.js                   # Frontend interactions
├── style.css                 # Frontend styles
├── style-sidebar.css         # Sidebar-specific styles
└── props.css                 # Additional property styles

link Key Components

REST API (inc/rest-api.php, inc/api/)

Schema Registration (inc/schema.php)

Templating (inc/templating.php, templates/)

link Configuration Options

Configure via t2.json in your theme root:

{
  "version": 1,
  "mu-extensions": [
    "t2/wiki",
    "t2/enable-generate-anchors",
    "t2/table-of-contents"
  ],
  "t2/wiki": {
    "postTypeKey": "wiki",
    "taxonomyTopicKey": "topic",
    "features": {
      "toc": true,
      "topicTree": true
    }
  }
}

link Configuration Reference

Key Type Default Description
postTypeKey string "wiki" Custom post type slug for wiki articles
taxonomyTopicKey string "topic" Taxonomy slug for topics
features.toc boolean true Enable table of contents meta field
features.topicTree boolean true Enable topic tree meta field

link Post Meta Keys

The extension registers the following post meta fields:

Both fields are:

link Enhanced WP_Post Object

The wiki extension enhances WP_Post objects with additional properties:

// After the_post() hook, wiki posts have:
$post->display_toc        // boolean: TOC enabled?
$post->display_topic_tree // boolean: Topic tree enabled?

This allows easy access in templates:

if ( $post->display_topic_tree ) {
    // Render topic tree sidebar
}

link Topic Tree System

Caching Strategy

Helper Functions (inc/schema.php)

// Get the full topic tree
$tree = \T2\Extensions\Library\Wiki\Schema\get_topic_tree(
    $with_empty_topics = false,
    $no_cache = false
);

// Each tree item contains:
// - term_id, name, slug, description, count
// - children (array of child topic items)

link REST API

The extension provides custom REST API endpoints under t2/wiki/v1 namespace:

Constants

T2_EXTENSIONS_WIKI_REST_API_PREFIX = 't2/wiki/v1'

See inc/rest-api.php and inc/api/ for endpoint implementations.

Block Name: t2/wiki-search

Attributes:

{
  "initialArticlesList": "empty|latest|manual",
  "maxNumberOfInitialArticles": 9,
  "manualArticles": [],
  "displayInitialArticlesTitle": true,
  "initialArticlesTitle": "Latest articles"
}

Frontend Behavior (view.js):

link Block: Wiki Topics

Block Name: t2/wiki-topics

Attributes:

{
  "selection": "all|manual|subtopics",
  "manualTopics": [],
  "subtopicsOf": 0,
  "articlesPerTopic": 10,
  "maxNumberOfTopics": 50,
  "hideArticlesCounter": false,
  "showSubtopicsOnly": false
}

Rendering:

link Helper Functions

get_wiki_post_type() (inc/config.php)
Returns the configured wiki post type key:

use function T2\Extensions\Library\Wiki\Config\get_wiki_post_type;

$post_type = get_wiki_post_type(); // 'wiki' by default

get_topic_taxonomy() (inc/config.php)
Returns the configured topic taxonomy key:

use function T2\Extensions\Library\Wiki\Config\get_topic_taxonomy;

$taxonomy = get_topic_taxonomy(); // 'topic' by default

get_taxonomy_terms_tree() (inc/helpers.php)
Build a hierarchical tree of taxonomy terms:

use function T2\Extensions\Library\Wiki\Helpers\get_taxonomy_terms_tree;

$tree = get_taxonomy_terms_tree(
    $taxonomy = 'topic',
    $parent_id = 0,
    $with_empty = false
);

The wiki extension automatically registers a card template for Featured Content Layout block:

register_featured_content_template(
    "post-type-{$wiki_post_type}",
    get_wiki_card_template()
);

This provides styled cards when displaying wiki articles in Featured Content blocks.

link Extension Dependencies

Required Extensions (must be enabled):

These dependencies are declared in extension.json:

{
  "extensionDependencies": [
    "t2/enable-generate-anchors",
    "t2/table-of-contents"
  ]
}

link Constants Defined

T2_EXTENSIONS_WIKI_PATH               // Path to wiki extension directory
T2_EXTENSIONS_WIKI_TEMPLATES_PATH     // Path to templates subdirectory
T2_EXTENSIONS_WIKI_REST_API_PREFIX    // REST API namespace (t2/wiki/v1)

link Development Tips

  1. Build required for JS changes: Run npm run build after editing view.js or editor files
  2. Transient cache: Clear transients during development: wp transient delete --all
  3. REST API testing: Use wp-json/t2/wiki/v1/ endpoints for API testing
  4. Topic tree performance: Large topic hierarchies benefit from caching; monitor transient usage
  5. Search customization: Modify view.js for frontend search behavior

link Hooks & Actions

Actions

init - Registers post type, taxonomies, and meta fields
the_post - Enhances WP_Post objects with wiki-specific properties
created_{$topic_taxonomy} - Clears topic tree cache
edited_{$topic_taxonomy} - Clears topic tree cache
delete_{$topic_taxonomy} - Clears topic tree cache

link Common Use Cases

Custom Search Results Template
Modify the search results rendering by editing templates in templates/ directory.

Add Custom Post Meta

add_action( 'init', function() {
    register_post_meta( 'wiki', 'custom_field', [
        'type'         => 'string',
        'single'       => true,
        'show_in_rest' => true,
    ] );
}, 11 ); // After wiki registers its post type

Customize Topic Display
Filter topic queries before rendering in the Wiki Topics block.

Extend REST API
Add custom endpoints under T2_EXTENSIONS_WIKI_REST_API_PREFIX namespace:

add_action( 'rest_api_init', function() {
    register_rest_route( T2_EXTENSIONS_WIKI_REST_API_PREFIX, '/custom-endpoint', [
        'methods'  => 'GET',
        'callback' => 'your_callback_function',
    ] );
} );

link Known Limitations