{"action":"created","issue":{"url":"https://api.github.com/repos/jtsternberg/Taxonomy_MetaData/issues/23","labels_url":"https://api.github.com/repos/jtsternberg/Taxonomy_MetaData/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/jtsternberg/Taxonomy_MetaData/issues/23/comments","events_url":"https://api.github.com/repos/jtsternberg/Taxonomy_MetaData/issues/23/events","html_url":"https://github.com/jtsternberg/Taxonomy_MetaData/issues/23","id":56193643,"number":23,"title":"Using custom tables instead of options for meta storage (extended class)","user":{"login":"underscorefunk","id":4334829,"avatar_url":"https://avatars.githubusercontent.com/u/4334829?v=3","gravatar_id":"","url":"https://api.github.com/users/underscorefunk","html_url":"https://github.com/underscorefunk","followers_url":"https://api.github.com/users/underscorefunk/followers","following_url":"https://api.github.com/users/underscorefunk/following{/other_user}","gists_url":"https://api.github.com/users/underscorefunk/gists{/gist_id}","starred_url":"https://api.github.com/users/underscorefunk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/underscorefunk/subscriptions","organizations_url":"https://api.github.com/users/underscorefunk/orgs","repos_url":"https://api.github.com/users/underscorefunk/repos","events_url":"https://api.github.com/users/underscorefunk/events{/privacy}","received_events_url":"https://api.github.com/users/underscorefunk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-02T03:58:12Z","updated_at":"2015-02-04T01:59:20Z","closed_at":null,"body":"First please let met apologize for if I've put this in the wrong place. I admit that I'm totally unfamiliar with git and community protocol. :(\r\n\r\nIn any event, I've never been a fan of throwing everything in the options table. I wrote a little extension to allow CMB2 to use custom tables instead of options. Just an idea I had. I've no doubt that there is a more elegant way to do this. Thanks for all of your hard work.\r\n\r\n```php\r\n<?php\r\n\r\nif ( ! class_exists( 'Taxonomy_MetaData_CMB2_mod' ) ) :\r\n\r\n/**\r\n * Allows custom meta for terms to be stored in taxonomy term meta tables\r\n * @version 0.0.1\r\n * @author  John Funk (Underscorefunk Design)\r\n */\r\n\r\nclass Taxonomy_MetaData_CMB2_mod extends Taxonomy_MetaData_CMB2 {\r\n\r\n\r\n\t/**\r\n\t * Meta type\r\n\t * @since  0.0.a\r\n\t * @var string\r\n\t */\r\n\tpublic $meta_type = '';\r\n\r\n\r\n\t/**\r\n\t * Meta table\r\n\t * @since  0.0.a\r\n\t * @var string\r\n\t */\r\n\tpublic $meta_table_name = '';\r\n\r\n\r\n\r\n\tpublic $object_type = '';\r\n\r\n\t\r\n\tpublic function __construct( $taxonomy, $metabox, $title = '', $option_callbacks = array() ) {\r\n\r\n\t\t$this->meta_type = $taxonomy . '_term';\r\n\t\t$this->object_type = 'taxonomy_metadata_' . $taxonomy;\r\n\t\tparent::__construct( $taxonomy, $metabox, '', $option_callbacks );\r\n\r\n\t\tadd_action( 'init', array( $this, 'create_meta_table' ) );\r\n\t\tadd_filter( 'cmb2_override_meta_value', array( $this, 'override_get_meta_value' ), 10, 4 );\r\n\t\tadd_filter( 'cmb2_override_meta_save',  array( $this, 'override_save_meta_value'), 10, 4 );\r\n\t}\r\n\r\n\t/**\r\n\t * Filter getting the meta value and extract the ID from params to perform proper get_metadata\r\n\t */\r\n\tpublic function override_get_meta_value( $object_id, $args, $object_type, $object ) {\r\n\t\tif ( strpos( $args, $this->object_type ) === 0 ) {\r\n\t\t\t$term_id = str_replace( $this->object_type . '_', '', $args );\r\n\t\t\treturn get_metadata( $this->meta_type, $term_id, $object_type['_id'], TRUE );\r\n\t\t}\r\n\t\treturn $object_id;\r\n\t}\r\n\r\n\t/**\r\n\t * Filter saving the meta value and extract the ID from params to perform proper get_metadata\r\n\t */\r\n\tpublic function override_save_meta_value( $check, $args, $field_args, $field_obj ) {\r\n\t\textract($args);\r\n\t\tif ( strpos( $id, $this->object_type ) === 0 ) {\r\n\t\t\t$term_id = str_replace( $this->object_type . '_', '', $id );\r\n\t\t\tupdate_metadata( $this->meta_type, $term_id, $field_id, $value );\r\n\t\t}\r\n\t\t\r\n\t\treturn $check;\r\n\t}\r\n\r\n\r\n\t/**\r\n\t * Creates a meta table for the custom taxonomy meta type\r\n\t * @since  0.0.1\r\n\t */\r\n\tpublic function create_meta_table() {\r\n\t\tglobal $wpdb;\r\n\t\t\r\n\t\t$this->meta_table_name = $wpdb->prefix . $this->meta_type . 'meta';\r\n\t\tcreate_metadata_table( $this->meta_table_name, $this->meta_type );\r\n\t\t$variable_name = $this->meta_type . 'meta';\r\n\t\t$wpdb->$variable_name = $this->meta_table_name;\r\n\t}\r\n\r\n\r\n\t/**\r\n\t * Returns term meta with options to return a subset\r\n\t * @since  0.1.3\r\n\t * @param  string  $term_id  The term id for the options we're getting\r\n\t * @param  string  $key      Term meta key to check\r\n\t * @return mixed             Requested value | false\r\n\t */\r\n\tpublic function get_meta( $term_id, $key = '' ) {\r\n\t\tif ( ! class_exists( 'CMB2' ) )\r\n\t\t\treturn;\r\n\r\n\t\t$this->do_override_filters( $term_id );\r\n\r\n\t\t$value = $key\r\n\t\t\t? get_metadata( $this->meta_type, $term_id, $key, TRUE )\r\n\t\t\t: get_metadata( $this->meta_type, $term_id ) ;\r\n\r\n\t\treturn $value;\r\n\t}\r\n\r\n}\r\n\r\nendif; // end class_exists check\r\n\r\n/* eof */\r\n```"},"comment":{"url":"https://api.github.com/repos/jtsternberg/Taxonomy_MetaData/issues/comments/72776474","html_url":"https://github.com/jtsternberg/Taxonomy_MetaData/issues/23#issuecomment-72776474","issue_url":"https://api.github.com/repos/jtsternberg/Taxonomy_MetaData/issues/23","id":72776474,"user":{"login":"jtsternberg","id":1098900,"avatar_url":"https://avatars.githubusercontent.com/u/1098900?v=3","gravatar_id":"","url":"https://api.github.com/users/jtsternberg","html_url":"https://github.com/jtsternberg","followers_url":"https://api.github.com/users/jtsternberg/followers","following_url":"https://api.github.com/users/jtsternberg/following{/other_user}","gists_url":"https://api.github.com/users/jtsternberg/gists{/gist_id}","starred_url":"https://api.github.com/users/jtsternberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtsternberg/subscriptions","organizations_url":"https://api.github.com/users/jtsternberg/orgs","repos_url":"https://api.github.com/users/jtsternberg/repos","events_url":"https://api.github.com/users/jtsternberg/events{/privacy}","received_events_url":"https://api.github.com/users/jtsternberg/received_events","type":"User","site_admin":false},"created_at":"2015-02-04T01:59:20Z","updated_at":"2015-02-04T01:59:20Z","body":"Very cool @underscorefunk. I'll definitely have to try this out sometime soon. Do you think this is vastly better than using the wp-large-options solution?"}}