WordPress Developer Ukraine, Kyiv
MySQL Common Table Expressions: Recursive Queries for Hierarchical Data

MySQL Common Table Expressions: Recursive Queries for Hierarchical Data

Recursive CTEs: query category trees and page hierarchies in MySQL WordPress stores hierarchies as parent pointers: a page has a post_parent, a category a parent in wp_term_taxonomy. Finding all descendants of an item needs one query per level in PHP, or a function like get_term_children() that loads the whole taxonomy into memory. A recursive common…
Register a custom post type in WordPress the right way

Register a custom post type in WordPress the right way

Register a custom post type in WordPress the right way WordPress has two built-in content types, posts and pages. As soon as a site needs structured content of another kind (portfolio items, events, team members, properties), putting it into posts with custom fields gets messy: the blog list mixes articles with team profiles, the editor…
WordPress wp_insert_term and wp_update_term: Manage Taxonomy Terms Programmatically

WordPress wp_insert_term and wp_update_term: Manage Taxonomy Terms Progr ...

Create, update and assign terms in code: wp_insert_term() and wp_set_post_terms() Imports and migrations need to create categories and other terms in code, often with a hierarchy, and then assign them to posts. WordPress has functions for both: wp_insert_term(), wp_update_term() and wp_delete_term() manage the terms, wp_set_post_terms() and wp_set_object_terms() attach them to posts. The details that matter…
WordPress Term Meta: add_term_meta, get_term_meta, and Custom Fields for Categories

WordPress Term Meta: add_term_meta, get_term_meta, and Custom Fields for ...

Term meta: custom fields for categories, tags and custom taxonomies Since WordPress 4.4 terms have their own meta table, and add_term_meta(), get_term_meta(), update_term_meta() and delete_term_meta() work like their post counterparts. Before that, plugins kept term data in options with keys like category_12_image. Term meta is the place for data that belongs to the term itself:…
Query posts by custom taxonomy term in WordPress

Query posts by custom taxonomy term in WordPress

Query posts by a custom taxonomy term in WordPress Categories and tags are the built-in taxonomies, but most projects also register their own: genre, location, brand. Sooner or later you need all posts of one term: portfolio items of one project type, products of one brand, the latest articles in a genre. The tool for…