Brush Up Your
Taxonomy Skills

A talk by @thorstenfrommen
‘ '  l I) I

W-I*_‘I i¥; IflIi I :3 ‘-_9;jI : I:>; ;I; :; I;  III I;  I_', *_'II I
In WordPress,  a taxonomy is a grouping mechanism for some posts. 

The names for the different groupings in a taxonomy ar...
where to Find
Taxonomies and Terms?
Admin:  Edit Terms

Sl'E4E’LI; IlC'1‘:  --en»

Categories

Search Categones

Add New Category Bulk Acnons -

5 Items

Name...
Admin:  Assign Terms

Add New Post

The Usage of Backbone. js in WordPress

PermalinkztIttp: I/examaIe. cam/2oI5/the-usage...
Front End:  Term Archive

Wordcamp Berlin 2015

‘III II  .  

Category:  Backbone. js

The Usage of Backbone. js in WordPr...
l-low to Use» Taxonomies
Programmatically?
Taxonomy Functions

register_taXonomy( $taxonomy,  $object_type,  $args ); 
if ( isitax( $taxonomy,  $term ) ) {
if ( isio...
Tax Query

 

'1-ravzuntomyy =0

       

 

 

‘sol 9
'i. -august;  =9
r*. ;:‘_y I
‘tmvzcoxntytttg =0 lfilgl
£. :.= t_leo...
Actions and Filters

I

addiaction(

1eqi: teIeditaxonomy',  function ( $taxonomy,  $objectitype ) {

},  ); 

addiaction(...
Taxonomies for Comments
Comment Taxonomies

 Must be separate taxonomies: 
r separate DB tables for posts and comments; 
r assign term to comment ...
Taxonomies for Users
User Taxonomies

I As with comment taxonomies,  must be separate taxonomies. 
o User taxonomies,  in general,  more useful...
Plugin:  User Taxonomies

<' Register a user taxonomy just like you do for post types. 

" "Ir= .b: (nu9)uy i . -‘I“‘! Ir,...
Plugin:  User Taxonomies

-‘:2‘u= :. = _ *gIIuu= nIt. .~

‘ up‘:  Lulu:  =9 = ,Ii"r'. =§Y '

 

ur= i,; to‘f1,nr= L_ I iiy...
Plugin:  User Taxonomies

 

Skills

Pupular skms Bulk Actions i Apply
3.. . N ]g_. :l; g'r; *' Front-end developmentl-eSt...
Plugin:  User Taxonomies

, ‘ Appeaianre

gi piugjm User Taxonomies

' Users

Departments Development

Backend development...
ileinlk Taxoinomies, 
aindl Synchronize ‘Their Terms
Linked Taxonomies

 Two (or more) taxonomies that share the same terms: 
H taxonomies registered for different sets of pos...
Linked Taxonomies

<2 Somehow manage linked taxonomies: 
r.  Which taxonomies are linked to each other? 
H Are there uni- ...
Plugin:  Linked Taxonomies

D:75il| JUd7Ll

Linked Taxonomies

categories Taxonomy Unidirectional Link Bidirectional Link
...
L. 
«.3
H
n
.  i
_
,4.
ii
. _ __
.1. , 
xv A4,,
Metadata,  by its very definition,  is information about information.  In the
case of WordPress,  it's information associa...
Metadata Examples

r Post metadata: 
I‘.  _edit_lock; 
I‘.  _menu_item_object_id; 
F _wp_page_template; 

F 

V User metad...
Metadata Functions

$adminicQlor :  getiuserimeta( $useriid, 
$relatOdiposts =  getipost_meta( $post id, 

update user met...
Meta Queries

   
   

'—- 9». -‘lie i‘ = .I, r‘1.Ir:5y ‘i
‘ iit; IZI! =i ha} =0 V _, or-‘tat; 
‘ utelirsi "3L_: .Ul$ 9 ‘ ...
Performance of Meta Queries

6 Metadata tables are not designed to get queried against by meta value: 
I".  there is no in...
”But I really DO have to
query by meta value! ?,, 

Meta Terms
to the Rescue!
Meta Taxonomy

r Use a separate taxonomy to store meta information: 
F use WP_Tax_Query instead of WP_Meta_Query; 

r.  hi...
Meta Tax Query

 

: -_ o_tIr= I,i ‘Y
? l_i'ZI? I‘§Y ‘

‘i. ‘3DZ(-’?1lll'«‘i)lIY # ‘ iit= Ii: ;

   

"i~. .:u, .:iira =0 ...
The Best of Both Worlds

 

‘ Lev: -,

  

 

 

guest 1 =9

 

   

       

l’= I'. ‘

"Iravzuniiotiiyy =0 ‘u-flat iii-....
Plugin:  Meta Taxonomy

it Very simple plugin to get you started: 
r registers a post meta taxonomy with (hopefully) appro...
Latest News
The WP_Term Class

0 Since WordPress 4.4.
o Replaces old stdClass objects. 

0 Static instance getter. 
0 Public propertie...
Term Meta

Not to be confused with meta terms (“/ )

0 Since WordPress 4.4.

0 Complete metadata support for terms: 
I sep...
T[’16i%

@thorstenfrommen

s| ides. tfr0mmen. de/ taxonomy/
Nächste SlideShare
Wird geladen in …5
×

Brush Up Your Taxonomy Skills

1.470 Aufrufe

Veröffentlicht am

Slides for the according talk at WordCamp Berlin, 2015

Veröffentlicht in: Internet
0 Kommentare
1 Gefällt mir
Statistik
Notizen
  • Als Erste(r) kommentieren

Keine Downloads
Aufrufe
Aufrufe insgesamt
1.470
Auf SlideShare
0
Aus Einbettungen
0
Anzahl an Einbettungen
26
Aktionen
Geteilt
0
Downloads
6
Kommentare
0
Gefällt mir
1
Einbettungen 0
Keine Einbettungen

Keine Notizen für die Folie

Brush Up Your Taxonomy Skills

  1. 1. Brush Up Your Taxonomy Skills A talk by @thorstenfrommen
  2. 2. ‘ ' l I) I W-I*_‘I i¥; IflIi I :3 ‘-_9;jI : I:>; ;I; :; I; III I; I_', *_'II I
  3. 3. In WordPress, a taxonomy is a grouping mechanism for some posts. The names for the different groupings in a taxonomy are called terms. —WordPress Codex
  4. 4. where to Find Taxonomies and Terms?
  5. 5. Admin: Edit Terms Sl'E4E’LI; IlC'1‘: --en» Categories Search Categones Add New Category Bulk Acnons - 5 Items Name Navre Slug Count B""‘b°"°-1‘ content Management systems (omen! -management-systems The name / S ham: appears D71)’(7L/ ISIIE —WordPress warcpress sIug batkbone—Is Programming p'ogvammIng me 'sIag' Is the UFIL-fiI€nd/ )'vE! SIoH o/ the name It rs usuauy aII/ tmmase and tolvmms only /6110: namam. ana'hypIIEII$ A javascript ; ax/ asmpt Parent Javascr-pt - _ _ jouew Categories anme lags. (an have a Inelalth, /. You nngm have a / at; Integrity, and under that have tmlaren tatsgones/ or Bebop and EIg Band. ToIaH, I optmflai Descnprron Backt>ane. Is gives structure to web applncauans by provldmg Nan‘? modeis wIth keyvvalue bundmg and tusmm events, collecnons wum _ a rich API of enumerable functions. mews with deciaratlve event Bulk Actions : handlmg. and connects I! all to your exusnng API over a RESTfuI JSON In: enace, | The d2s(. 'IptIon 15 not prominent by de/ cu/ L‘ Imwevtv, same theme: may show It,
  6. 6. Admin: Assign Terms Add New Post The Usage of Backbone. js in WordPress PermalinkztIttp: I/examaIe. cam/2oI5/the-usageef-ta. ..s-In-wordpresy Em! VIewPos: 0,: Add Media Vm lk D-quule «I ms tmg ul oI eaae more dasetag: Loren ipsum aatar sit net, tansetelur sldipsting eutr, sed diam rlnnumy esrmsa tempnr invidunt ut labor: et aatare lngna aliquyarl erat, sea diam voluplua. at VEVO eos et actasan et justo duo dolores et ea rebum. Stet cute kasd gubergren, nv sci takimata sanctus est Lorem iusull dolor sit amet. Loren! ipsum dolor sit nut, consetetur sadipscing elitr, sed diam nonumy einwd teapar invidunt In: labore et dolcre nagni aliquyavl erat, sed diam veluptua. At vero eos et accusan et justo duo dolcres et ea rebum. stat elita kasd gubergren, no sea takinlara sinnus est Lorem ipsun dolor sit aIret. | Ward zounz. I00 Draft saved at I0 ISIOG pm. srIt-on npt cw: Publish Save otart ? status: Draft E @ VISIbI| I[yI Publlt gag E Dubhsh immediateIy :93 Move to Trash Categories AII categones vuost Used content Management systems i WordDIesS vrogramrrIIng _ Iavastrtpt ii BacI<bone. Is . . JQI. ery : PHP mn
  7. 7. Front End: Term Archive Wordcamp Berlin 2015 ‘III II . Category: Backbone. js The Usage of Backbone. js in WordPress '4 November 20l5 Lotem ipsum dolor sit amet, consetetut sadipscing elitt, sed diam nonumy Earkbonels Wovdpwss eitmod tempot invldunt ut labote et dolote Inagna aliquyam etal, sed diam voluptua. At veto eos et accusam et justo duo dolotes et ea tebum. Stet clita FIN kasd gubetgten, no sea takimata sanctus est Lotem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod Iempor invldunt ut Iabote et dc-lore magna aliquyam erat, sed diam voluptua. At veto eos et accusam et justo duo dolotes et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Leavea comment CATEGORIES II~IIII .1ll'Il’Iltll‘ : ll'l
  8. 8. l-low to Use» Taxonomies Programmatically?
  9. 9. Taxonomy Functions register_taXonomy( $taxonomy, $object_type, $args ); if ( isitax( $taxonomy, $term ) ) { if ( isiobjectiinitaxonomy( $objectitype, $taxonomy ) ) { if ( hasiterm( $term, $taxonomy, $post ) ) { wp_set_object_terms( $object_id, $terms, $taxonomy ); $terms = getiterms( $taxonomy, $args ); $objects = get_objects_in_term( $term, $taxonomy, $args );
  10. 10. Tax Query '1-ravzuntomyy =0 ‘sol 9 'i. -august; =9 r*. ;:‘_y I ‘tmvzcoxntytttg =0 lfilgl £. :.= t_leo‘l =9 "ta-signs»: =0 I ‘vztolbteu.
  11. 11. Actions and Filters I addiaction( 1eqi: teIeditaxonomy', function ( $taxonomy, $objectitype ) { }, ); addiaction( 'cIwntwd twtm‘, function ( $term_id, $tt_id, $taxonomy ) { lr function ( $term, $taxonomy ) {
  12. 12. Taxonomies for Comments
  13. 13. Comment Taxonomies Must be separate taxonomies: r separate DB tables for posts and comments; r assign term to comment with ID 1 —> also assigned to post with ID 1. cs Use cases: H type (e. g., bug, enhancement, feature request); r urgency (e. g., low, moderate, high); H
  14. 14. Taxonomies for Users
  15. 15. User Taxonomies I As with comment taxonomies, must be separate taxonomies. o User taxonomies, in general, more useful than comment taxonomies. 0 Use cases: I department (e. g., design, development, project management); I interest (e. g., diving, music, programming); I skill (e. g., back—end development, front—end development, testing); I . .
  16. 16. Plugin: User Taxonomies <' Register a user taxonomy just like you do for post types. " "Ir= .b: (nu9)uy i . -‘I“‘! Ir, =.v: (oIun9): Iv1— ‘Imam = .1—: II*= .y * ~-":1‘u= a,. :, ,,. "gn-uu= u-': .. ~ ‘ grqgrzlbng _l '. "1 gen‘ 9 ‘m= nr= ugr= t: =It: m= 'll€¢= I,: ‘ aitl ‘I. “w= I_l: uu»~ lrsvalns‘ o‘! -., l.= I‘r, .-. — i; =I, r:ur, = II‘-T'= I,u‘= ‘ ‘ = r-‘#1143111 'K= I,x: m= I‘zi'u= :. : _ . 'gIIIm= nI"1_. ~ / ** @see github. com/ tfrommen/ user—taxonomies */
  17. 17. Plugin: User Taxonomies -‘:2‘u= :. = _ *gIIuu= nIt. .~ ‘ up‘: Lulu: =9 = ,Ii"r'. =§Y ' ur= i,; to‘f1,nr= L_ I iiy —_-9 21. ‘ = .; , L.w. -‘_-. Iuu, _c-’r. _v, => i. ;>r: I,l; . ‘ ‘1:; urgp. ~ =9 ‘; _;/ mule. ‘ 31: 1.0; I _n= v.~ :6 t, :_r'I_(; . It fuel. =. L ‘gluuueuii _. ~ / ** @see github. com/ tfrommen/ user—taxonomies */
  18. 18. Plugin: User Taxonomies Skills Pupular skms Bulk Actions i Apply 3.. . N ]g_. :l; g'r; *' Front-end developmentl-eStIl'lg Nam l Bacloend development Add New Skill NW"! Front-end development DESlg| 'l The name /5 ha», :2 appears on , ’(7LlFS€tE "fling Slug N arre design we ’slug"rs the L/ ‘7it—fHendl, ' uerxron rvflhe name / : rs usuallyali /0.'. €V(GS€ am iaqtalfls on/ y/crtsrs mnrms ana hyphens Bulk Anions 7 Apply oes: r., .m rm des('ip. ’iL‘n 75 not pnminem by defauvr: haavsvev, same rilsmes may Show n. / ** @see github. com/ tfrommen/ user-taxonomies */ DESUIDIIOH Desorption Slug Da(k enc-develoG’nenl from endrz: e.‘e! o:v'ne'it testing Slug Use: 5 Users m. .yv: .;u .2 Search ski is
  19. 19. Plugin: User Taxonomies , ‘ Appeaianre gi piugjm User Taxonomies ' Users Departments Development Backend development Front-end development Testing Your Profile Interests Mammm Ofjwrms x Diving x Music x Programming f T oi: ils II] settings lJ'. )ddlP Vlufllv O / ** @see github. com/ tfrommen/ user—taxonomies */
  20. 20. ileinlk Taxoinomies, aindl Synchronize ‘Their Terms
  21. 21. Linked Taxonomies Two (or more) taxonomies that share the same terms: H taxonomies registered for different sets of post types; H taxonomies registered for different object types; F. one visible source taxonomy linked to one or more hidden target taxonomies. «t Propagate changes to one taxonomy's terms to all linked taxonomies.
  22. 22. Linked Taxonomies <2 Somehow manage linked taxonomies: r. Which taxonomies are linked to each other? H Are there uni- or bidirectional relationships? 6 Hook into relevant actions: I“. created_term; F edit_terrns; F edited_term_taxonomy; F delete_term.
  23. 23. Plugin: Linked Taxonomies D:75il| JUd7Ll Linked Taxonomies categories Taxonomy Unidirectional Link Bidirectional Link rrilegn/ y rags um: ii, -,4 Ci 3 is Dmm‘ “ Navigation Menus rim iiisri. Appoaiantc _ WW5 Link Categories UF‘€. '_liZ. ’i"i’l' Metas "it'll: 1335 Taxonomy Unidirectional Link Bidirectional Link poxrjag Categoi ies rri: tji: nij. ' Taxonomies Navigation Menus i’lflt_"‘L‘I C) 0 Link Categories / ** @see github. com/ tfrommen/ |inked—taxonomies */
  24. 24. L. «.3 H n . i _ ,4. ii . _ __ .1. , xv A4,,
  25. 25. Metadata, by its very definition, is information about information. In the case of WordPress, it's information associated with content in the comments, posts, or users table. —WordPress Plugin Handbook
  26. 26. Metadata Examples r Post metadata: I‘. _edit_lock; I‘. _menu_item_object_id; F _wp_page_template; F V User metadata: I‘. admin_color; F first_name; F meta—box—order_post;
  27. 27. Metadata Functions $adminicQlor : getiuserimeta( $useriid, $relatOdiposts = getipost_meta( $post id, update user meta( $user id, deleteipostimeta( $pgsL id,
  28. 28. Meta Queries '—- 9». -‘lie i‘ = .I, r‘1.Ir:5y ‘i ‘ iit; IZI! =i ha} =0 V _, or-‘tat; ‘ utelirsi "3L_: .Ul$ 9 ‘ i. =nir_o. L. ;Ii; :a. ~.. ‘ _. "‘Itl l —*v. 'i'. _o‘I'li‘o. gzfiggi :19} =9 , , , .wn“t _, ur= Iiit= ‘ vs, i It; =0 flan; Kay I . =rzI’t u= Iiit=
  29. 29. Performance of Meta Queries 6 Metadata tables are not designed to get queried against by meta value: I". there is no index on the meta_value column; r. there is an index on the column holding the related object's ID; r. also, the (start of the) meta key is indexed. ~' Query against metadata tables by F object ID: great, that's how it's supposed to be; if object ID and meta key: also great; n meta key: perfectly doable.
  30. 30. ”But I really DO have to query by meta value! ?,, Meta Terms to the Rescue!
  31. 31. Meta Taxonomy r Use a separate taxonomy to store meta information: F use WP_Tax_Query instead of WP_Meta_Query; r. hierarchical taxonomy for more complex conditions; r it's fast! Clearly, this is not possible with every metadata query.
  32. 32. Meta Tax Query : -_ o_tIr= I,i ‘Y ? l_i'ZI? I‘§Y ‘ ‘i. ‘3DZ(-’?1lll'«‘i)lIY # ‘ iit= Ii: ; "i~. .:u, .:iira =0 '—{_o--mi ‘
  33. 33. The Best of Both Worlds ‘ Lev: -, guest 1 =9 l’= I'. ‘ "Iravzuniiotiiyy =0 ‘u-flat iii-. vIZIr= i A 'i. .‘yI, .JiIr; =9 lI’= l€‘ = I9I. ¢I9 i Imam‘ i - ‘Jr ; IIs«eI_-re = .-. ~ L-‘III. r;«eI; r - '-1" natal; ,1:-Iiraii . -‘i0.IIs«; I,r*
  34. 34. Plugin: Meta Taxonomy it Very simple plugin to get you started: r registers a post meta taxonomy with (hopefully) appropriate arguments; r can be heavily customized by filters (e. g., to work with comments or users). r Comes with a function to check if a given object has a given meta term. if ‘lfjif luteiivra “Italian: -i . ~‘§i91‘cr‘I; -oi‘! :-o‘L . ~‘1tit; I“Ir, =i “Ital, -viii‘ in‘! ur slstgi i $1915“ ' I‘= I‘r "H: A / ** @see github. com/ tfrommen/ meta—taxonomy */
  35. 35. Latest News
  36. 36. The WP_Term Class 0 Since WordPress 4.4. o Replaces old stdClass objects. 0 Static instance getter. 0 Public properties, just like before. $term : WPiTerm: :getiin5tance( $termiid ); if ( $term && 'wurdvamy' : :: $term->taxonomy ) { echo $term—>name; $newiterm : new WPiTerm( (object) array( ‘name’ : > 'Npw term in tho wild‘, );
  37. 37. Term Meta Not to be confused with meta terms (“/ ) 0 Since WordPress 4.4. 0 Complete metadata support for terms: I separate {$table_prefix}_termmeta table; I *_term_meta() functions; I meta_query parameters for term getters. 0 Use cases: I term image; I related terms; I
  38. 38. T[’16i% @thorstenfrommen s| ides. tfr0mmen. de/ taxonomy/

×