WordPress.org

Ready to get started?Download WordPress

Forums

Grabbing menu info from another wp site (4 posts)

  1. tempestjonny
    Member
    Posted 1 year ago #

    Hey everyone.

    I've got multiple WP sites, each with their own flavor, but I'm putting together a Plugin to add a global header across them all. In this header i want a menu from 1 of the WP sites.

    So what i'm looking for is a way to use "wp_nav_menu" in a plugin, to get the menu from a Specific WP installation. I'm sure i remember reading a way to do it by temporarily swapping "$wpdb" info. I have tried to find said info again, with little success.

    Does anybody know of a way to either use the "wp_nav_menu" function in this way, or any other way i may be able to get the menu off another WP Installation?

  2. bcworkz
    Member
    Posted 1 year ago #

    Redefining $wpdb may work, worth a try.

    $localdb = $wpdb;
    $wpdb = new wpdb( REMOTE_DB_USER, REMOTE_DB_PASSWORD, REMOTE_DB_NAME, REMOTE_DB_HOST );
    //do $args and wp_nav_menu() stuff here
    $wpdb = $localdb;

    The static parameters do not exist, they are only examples, you need to put in the actual values for the "remote" site. I don't know if that's all there is to this or not, it's easy enough to be worth trying.

    Another method might be to create a page on the remote site that does nothing but display the menu, then call it inside an iframe from the other sites.

  3. tempestjonny
    Member
    Posted 1 year ago #

    Thanks for the advice. I've given it a try. I think changing the "$wpdb" only effect getting info directly from the database. When i used it in conjunction with "wp_nav_menu" it seemed to yield no results.

    I even tried using "bloginfo( url )" to see which site, if any, it would grab the info from. Even using the "$wpdb" fix above resulted in the info from the local site being produced.

    Official :(

  4. bcworkz
    Member
    Posted 1 year ago #

    I did a classic noob mistake... we must have the line global $wpdb; in the function or on the template somewhere.

    I don't know if adding it will help, but it will not work without it. You may have caught this, but either way, my apologies.

Topic Closed

This topic has been closed to new replies.

About this Topic