Tremendous Taxonomies

Tremendous Taxonomies

Taxonomies have been around in WordPress for a long time as a way of grouping things together, but did you know there is a lot you can do with taxonomies which you may not know? In this talk I will outline what taxonomies are and how you can create your own custom taxonomies. I will share some use cases for having custom taxonomies as well as some different and interesting ways in which I have used taxonomies on some sites in the past. In addition I will looks at some of the ways in which you can optimise the admin UI for taxonomies, making it more appropriate in some cases. The talk will also look at how you can associate data with different taxonomy terms.

31af50af29856a3e6734bdae0a0d68cf?s=128

Mark Wilkinson

October 22, 2016
Tweet

Transcript

  1. Tremendous Taxonomies WordCamp Manchester 2016 @wpmark markwilkinson.me highrise.digital

  2. “a classification into ordered categories” dictionary.com

  3. Grouping & Organising Content

  4. Default Taxonomies Categories / category Tags / post_tag Link Category

    / link_category Post Formats / post_format Menus / nav_menu
  5. Custom Taxonomies

  6. function hd_register_tax() { register_taxonomy( $taxonomy, $objects, $args ); } add_action(

    ‘init’, ‘hd_register_tax’ );
  7. labels show_ui show_in_menu hierarchical meta_box_cb

  8. hierarchical true false

  9. meta_box_cb https://github.com/highrisedigital/highrise-taxonomy-ui https://github.com/johnbillion/extended-taxos

  10. wp_query https://10up.github.io/Engineering-Best-Practices/php/

  11. $news = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page =>

    -1, ‘meta_query’=> array( array( ‘key’ => ‘home_slider’, ‘value’ => ‘yes’ ) ) ) );
  12. $news = new WP_Query( array( ‘post_type’=> ‘post’, ‘posts_per_page => 100,

    ‘tax_query’ => array( array( ‘tax’=> ‘locations’, ‘field’=> ‘slug’, ‘terms’=> ‘home-slider’ ) ) ) );
  13. None
  14. Bookmarks https://www.flickr.com/photos/roxeteer/4326217872

  15. User Bookmarks Logged in users can bookmark posts The are

    saved into a bookmarks page for each user Bookmarked posts can be removed from this page
  16. user_register wp_insert_term() wp_set_object_terms() wp_set_object_terms()

  17. add_action( 'user_register', hd_add_user_bk_term ); function hd_add_user_bk_term( $user_id ) { wp_insert_term(

    'user-' . $user_id, 'hd_bookmark', $args // term desc etc. ); }
  18. $post_id = absint( $_POST[ 'postid' ] ); $user_id = absint(

    $_POST[ 'userid' ] ); $term = get_term_by( 'slug', 'user-' . $user_id, 'hd_bookmark' ); if( $term != false ) { wp_set_object_terms( $post_id, $term>term_id, 'hd_bookmark', true ); }
  19. $post_id = absint( $_POST[ 'postid' ] ); $user_id = absint(

    $_POST[ 'userid' ] ); $term = get_term_by( 'slug', 'user-' . $user_id, 'hd_bookmark' ); if( $term != false ) { wp_remove_object_terms( $post_id, $term- >term_id, ‘hd_bookmark ); }
  20. Term Meta http://themehybrid.com/weblog/introduction-to-wordpress-term-meta

  21. https://wordpress.org/plugins/wp-term-icons/

  22. https://wordpress.org/plugins/wp-term-colors/

  23. {$tax}_edit_form_fields {$tax}_add_form_fields edit_{$tax} create_{$tax}

  24. {$tax}_add_form_fields

  25. {$tax}_edit_form_fields

  26. Not Just Post Types User Taxonomies

  27. None
  28. WordPress Development WordCamp Manchester 2016 Bronze Sponsors

  29. Thank you & Questions? Twitter: @wpmark WordPress: @wpmarkuk markwilkinson.me highrise.digital