WordPress.org

Ready to get started?Download WordPress

Forums

Changing Table_Prefix on fly (1 post)

  1. lty83
    Member
    Posted 3 years ago #

    Is there an easy way to pull a WP_NAV_MENU from a different wordpress DB than is being used under the current installation?

    The reason being is I had to install a "sub dir" of wordpress in order to run 2 themes, my core theme being the "Front End" then my directory theme for my wordpress directory plugin (running off a sub directory of my core site)

    Now - i'd like to make it so that if I make changes to the navigation menu on my core WP install it is also reflected in my sub direct wp install. I was hoping there would be a way I could change the DB connection string so that when i call WP_NAV_MENU on my sub installation it actually pulls from my other db - does this make sense? Would save me a TON of time...

    So, is there anyway i can change the connection string temporarily in coding, for example

    $db = "different db connection";
    wp_nav_menu( array('menu' => 'MyMenuName' ));
    $db = "reset to original connection string";

    Another note - i attempted this on my code inline:

    $table_prefix = 'wp_';
    wp_nav_menu( array('menu' => 'Header Menu' ));
    $table_prefix = 'dir_';

    but no luck, the wp_nav_menu is still pulling from the "dir_" prefixed tables instead of the "core" "wp_" prefixed tables.

    also attempted:

    $wpdb->prefix = 'wp_';
    wp_nav_menu( array('menu' => 'Header Menu' ));
    $wpdb->prefix = 'dir_';

    no go tho...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.