Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
I was searching for an answer to this problem as well, with no luck, so I really hope, someone can answer it. –  petermolnar May 2 '11 at 11:17

1 Answer 1

Yep, just declare global $wpdb early enough and modify its fields. Codex docs for add_metadata() say exactly that:

Note that you will also have to register the table with the $wpdb object in order for it to work. Simply add the following to WordPress' init hook (or at least before you attempt to use any custom metadata functions).

global $wpdb;
$wpdb->termmeta = $wpdb->prefix.'termmeta';
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.