There is a problem: I want to add a table ‘linkmeta’ to work like ‘postmeta’ or ‘commentmeta’.. and use functions like add_metadata / update_metadata / delete_metadata!
but, in this functions call “_get_meta_table()” to verify the name in db, this code:
function _get_meta_table($type) {
global $wpdb;
$table_name = $type . 'meta';
if ( empty($wpdb->$table_name) )
return false;
return $wpdb->$table_name;
}
so, if doesn’t exist the property/var named ‘linkmeta’ in $wpdb, _get_meta_table
will return false, then update_metadata
too will not work, because this piece of code at begin of that:
if ( ! $table = _get_meta_table($meta_type) )
return false;
but, if I can set a property/var of (class) $wpdb
like $wpdb->linkmeta
return the correct name of table, in this case (default) wp_linkmeta, all the rest will work NICE!
so, there is a way to change wpdb in runtime?
if I just put the commands:
$wpdb->tables = array_merge($wpdb->tables, array('linkmeta'));
$wpdb->linkmeta = $wpdb->prefix . 'linkmeta';
at plugin initialize, will it work when function _get_meta_table
is called??!
rgds
Yep, just declare global
$wpdb
early enough and modify its fields. Codex docs foradd_metadata()
say exactly that: