I'm trying to create a custom meta table, that uses the functionality already written into WP.

function get_mytype_meta( $post_id, $key = '', $single = false ) {
    return get_metadata( 'mytype', $post_id, $key, $single );

function add_mytype_meta( $sid, $meta_key, $meta_value, $unique = false ) {
    return add_metadata( 'mytype', $sid, $meta_key, $meta_value, $unique );

function update_mytype_meta( $sid, $meta_key, $meta_value, $prev_value = '' ) {
    return update_metadata( 'mytype', $sid, $meta_key, $meta_value, $prev_value );

What is stopping this from working so far, is the function _get_meta_table which then requires the table {wpdb->prefix}mytypemeta to be listed in $wpdb already. I'm not sure where to do that.

Please advise. Greatly appreciated!

1 Answer 1


I found my answer by just digging through wp-includes/meta.php ... I just had to add to $wpdb myself at runtime.

add_action('init', function(){
    global $wpdb;
    $wpdb->mytypemeta = "{$wpdb->prefix}mytypemeta";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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