Taxonomieën - Datamodel (WordPress, 2022)
Zo zitten WordPress-taxonomieën op database-niveau in elkaar:
Inleiding
Een standaard-WordPresssite bevat al snel een handjevol taxonomieën. Daarnaast kunnen plugins hun eigen taxonomieën toevoegen. Een impressie van een live webwinkel:
> select distinct taxonomy from wp_term_taxonomy; action-group category nav_menu pa_widget_code pa_automatische_stop pa_breedte pa_connector pa_diagram pa_diepte pa_lengte pa_materiaal pa_originele_widget pa_productlijn pa_stroomdraad pa_toepassing_model pa_toepassing_soort pa_toepassing_submodel pa_veer product_cat product_type product_visibility > select attribute_name from wp_woocommerce_attribute_taxonomies; widget_code automatische_stop breedte connecteur diagramme profondeur longeur widget_origine fil_electrique application_modele application_sous_modele ressort gamme_produits application_type materiel
Soorten & maten
Taxonomieën komen in verschillende smaken en soorten. Een mogelijke indeling:
- Attributes (algemeen - Kenmerken)
- Categories (algemeen)
- WooCommerce Attributes
- WooCommerce Categories -
product_cat
- Tags (WooCommerce).
Dit artikel gaat vooral over WooCommerce Categories en WooCommerce Attributes.
Alle taxonomieën staan in wp_term_taxonomy
In beginsel vind je alle taxonomieën terug in tabel wp_term_taxonomy
. Een paar elementen uit het voorbeeld hierboven iets nader bekeken:
action-group - ? category - Reguliere Category-taxonomie nav_menu - Menu-items worden bijgehouden middels een taxonomie pa_widget_code - Een WooCommerce Attribute pa_breedte - Een WooCommerce Attribute product_cat - WooCommerce Category product_tag - WooCommerce Tags product_type - WooCommerce: Verschillende soorten producten (simple, virtual, etc.) product_visibility - ?
Terms & associated taxonomies
All terms (from all taxonomies) are stored in table wp_terms
. E.g.:
select * from wp_terms order by length(name) desc
This probably doesn't convey much information, so let's combine it with some data from wp_term_taxonomy
:
select term_id, name, slug, taxonomy, description, parent, count from wp_terms join wp_term_taxonomy using (term_id) order by length(name) desc
Number of terms per taxonomy:
select taxonomy, count(taxonomy) from wp_terms join wp_term_taxonomy using (term_id) group by taxonomy;
An impression (2022.10.17 - eur_en):
Number Taxonomy of terms Notes ------------------ -------- ---------------------- action-group 1 Internal. No touching! pa_auto 2 Just two taxons: With & without pa_conn 2 Just two taxons: With & without pa_hou 2 Just two taxons: With & without pa_mat 2 Just two taxons: With & without pa_productlijn 2 Just two taxons: A & B pa_stroom 2 Just two taxons: With & without pa_veer 2 Just two taxons: With & without category 4 Probably the "category taxonomy" for posts & pages. Used here by accident? product_type 4 Internal (WooCommerce). No touching! nav_menu 5 Internal (WordPress). No touching! product_visibility 9 Internal (WooCommerce). No touching! pa_apparaat 54 pa_breedte 88 pa_lengte 110 pa_diepte 120 pa_diagram 149 product_cat 745 product_cat is used here like "brand » device" pa_sku_oem_code 1433 pa_originele_widget 1543 pa_submodel 9652 pa_model 12641
Everything starting with pa_
is a WooCommerce product attribute taxonomy. There are 16 product attribute taxonomies on this site.
Transients
Naast de diverse Caching-plugins die in een WordPress-installatie mogelijk rondzwerven, is er ook een 'interne' vorm van caching: Rijen in tabel wp_options
met het keyword _transient_
in veld option_name
. Ik had in de loop van 2019 of 2020 last van deze vorm van caching rondom het aanpassen van atributen.
Je kunt Deze transients probleemloos verwijderen. Wellicht handig om altijd te doen rondom werken met categorieën:
delete from wp_options where option_name like '_transient_%'
Zie [1] voor details.
product_cat
product_cat
, oftewel Product Categories of WooCommerce Categories, zijn een specifiek geval van de algemene Categories-functionaliteit van WordPress. Er is geen overlap tussen de algemene- & WooCommerce-variant van deze taxonomie- Er is maar één WooCommerce Categories-taxonomie. Deze kan echter wel meerdere begintaxa hebben. Op die manier kun je via een omweg meerdere taxonomieën incorporeren.
Velden & locatie
- Tabel
wp_terms_taxonomy
: Type taxonomy (product_ca
) + description, gekoppeld aan een term (=taxon) - Tabel
wp_terms
: Slug & taxonnaam - Tabel
wp_termmeta
: order, display_tyoe, thumbnail_id en eventuele maatwerk-velden.
Nieuw begintaxon aanmaken
Dit is een gemakkelijk voorbeeld. Als je hier doorheenkomt, snap je 't waarschijnlijk helemaal:
Product category text - wp_termmeta
Ik heb de indruk (mei 2021) dat je voor categorieën je eigen velden en attributen kunt defineren, vergelijkbaar met 'algemene' attributen in tabel wp_postmeta
. Voor categorieën vind je deze in tabel wp_termmeta
.
Voorbeeld:
WooCommerce Attributes
- WooCommerce Attributes oftewel Kenmerken, zijn de niet-hiërarchische tegenpool van WooCommerce Categories
- Attributes zijn niet-hiërarchisch: Er is maar één rang. Die ene rang kan echter wel een onbeperkt aantal taxa bevatten.
Definitie van een attribute taxonomy
De definitie van een WooCommerce Category is verspreid over drie tabellen wp_term_taxonomy
, wp_terms
en wp_termmeta
. Voor Attribute taxonomies ligt dat iets anders, omdat deze geen equivalent heeft voor niet-WooCommerce-objecten en omdat elke attribute een eigen taxonomie betreft:
- Taxonomie-definities worden bijgehouden in tabel
wp_woocommerce_attribute_taxonomies
- Tabel
wp_term_taxonomy
is de link tussen het specifieke WooCommerce-gedeelte, en de reguliere taxonomie-functionaliteit van WordPress - Link:
wp_woocommerce_attribute_taxonomies.attribute_name
is het gedeelte napa_
vanwp_term_taxonomy.taxonomy
select * from wp_woocommerce_attribute_taxonomies; +--------------+-------------------------+-----------------------------+----------------+-------------------+------------------+ | attribute_id | attribute_name | attribute_label | attribute_type | attribute_orderby | attribute_public | +--------------+-------------------------+-----------------------------+----------------+-------------------+------------------+ | 16 | widget_code | Code Widget | select | menu_order | 1 | | 17 | automatische_stop | Arrêt automatique? | select | menu_order | 1 | | 18 | breedte | Largeur (mm) | text | menu_order | 1 | | 19 | connecteur | Connecteur? | select | menu_order | 1 | | 20 | diagramme | Diagramme | text | menu_order | 1 | | 21 | profondeur | Profondeur (mm) | text | menu_order | 1 | | 22 | longeur | Longeur (mm) | text | menu_order | 1 | | 23 | Widget_origine | Widget d'origine | select | menu_order | 1 | | 24 | fil_electrique | Fil électrique? | select | menu_order | 1 | | 25 | application_modele | Application - Modèle | select | menu_order | 1 | | 26 | application_sous_modele | Application - Sous-modèle | select | menu_order | 1 | | 27 | ressort | Ressort? | select | menu_order | 1 | | 28 | gamme_produits | Gamme de produits | select | menu_order | 1 | | 29 | application_type | Application - Type | select | menu_order | 1 | | 30 | materiel | Matériel | select | name | 1 | +--------------+-------------------------+-----------------------------+----------------+-------------------+------------------+