Build WordPress plugins from scratch: actions and filters, shortcodes, settings pages, custom post types, meta boxes, AJAX, REST endpoints, custom tables, cron and blocks.
Lessons
A custom taxonomy is a way of grouping content — like categories and tags, but your own — registered with register_taxonomy() and attached to one or more post types.
<?php
function gdc_books_register_taxonomies() {
register_taxonomy(
'gdc_genre',
array( 'gdc_book' ),
array(
'labels' => array(
'name' => _x( 'Genres', 'taxonomy general name', 'gdc-books' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name', 'gdc-books' ),
'add_new_item' => __( 'Add New Genre', 'gdc-books' ),
'search_items' => __( 'Search Genres', 'gdc-books' ),
'all_items' => __( 'All Genres', 'gdc-books' ),
'parent_item' => __( 'Parent Genre', 'gdc-books' ),
),
'hierarchical' => true, // Category-style, with parents and checkboxes.
'public' => true,
'show_admin_column' => true, // A Genre column in the Books list.
'show_in_rest' => true, // Required for the block editor panel.
'rewrite' => array( 'slug' => 'genre' ),
)
);
register_taxonomy(
'gdc_book_author',
array( 'gdc_book' ),
array(
'labels' => array(
'name' => __( 'Book Authors', 'gdc-books' ),
'singular_name' => __( 'Book Author', 'gdc-books' ),
),
'hierarchical' => false, // Tag-style: type names freely.
'show_admin_column' => true,
'show_in_rest' => true,
'rewrite' => array( 'slug' => 'book-author' ),
)
);
}
add_action( 'init', 'gdc_books_register_taxonomies' );Hierarchical (true) | Flat (false) | |
|---|---|---|
| Behaves like | Categories | Tags |
| Editor UI | Checkbox list, with parents | Type-and-add field |
| Good for | A fixed structure: Fiction → Fantasy | Open-ended labels: author names |
Watch out: Taxonomy keys are limited to 32 characters and must not clash with core names.author,category,tag,typeandyearare reserved query variables — using them breaks archives in confusing ways. That is why this lesson usesgdc_book_author.
| Use a taxonomy when | Use a custom field (post meta) when |
|---|---|
| Many posts share the value | The value is unique to one post (ISBN) |
| Visitors should browse by it | It is only displayed, never browsed |
| You will query by it often | You rarely or never query by it |
Taxonomy queries use indexed relationship tables and stay fast on large sites. That makes "genre" a perfect taxonomy and "ISBN" a perfect custom field.
<?php
// Assign genres to a book (replaces existing ones).
wp_set_object_terms( $book_id, array( 'fantasy', 'adventure' ), 'gdc_genre' );
// Read them.
$genres = get_the_terms( $book_id, 'gdc_genre' );
if ( $genres && ! is_wp_error( $genres ) ) {
$names = wp_list_pluck( $genres, 'name' );
echo esc_html( implode( ', ', $names ) );
}
// Create default terms on activation.
if ( ! term_exists( 'Fiction', 'gdc_genre' ) ) {
wp_insert_term( 'Fiction', 'gdc_genre' );
}/genre/fantasy/ and see the archive (flush permalinks if it 404s).term_exists() and wp_insert_term().In accordance with Section 6 & Section 7 of the DPDP Act 2023, third-party analytics and marketing trackers are strictly gated behind your affirmative consent. You may withdraw consent at any time under Section 6(4).
Essential for session authentication (ci_session), Cross-Site Request Forgery security (csrf_cookie_name), and Cloudflare DDoS/bot prevention. Cannot be disabled.
Gated under DPDP Section 7. Allows Google Analytics 4 (Google Consent Mode v2) to measure aggregate, anonymized tool usage.
Enables browser local storage to preserve your theme selection (dark/light mode) and code editor layout between visits.
Used to display developer sponsorships and native tool partner notices.