Improved Include Page
[resolved] How to Include Page to an other Multiblog-Site (9 posts)

  1. bhenselmann
    Posted 4 years ago #

    I'ld like to include a page from one WP-Site in to an other WP-Site. Both sites are in the same WP-Multisite installation.
    Has anybody an idea how to resolve this?

  2. At a guess ... You know where you make these calls:
    <?php echo iinclude_page(4, null, true); ?>

    Before that echo, you would want to use switch_to_blog().

    CAVEAT Doing this a bunch of times will slow your site down, so be cautious.

  3. And also clicking those links will literally take the viewer to the other blog.

  4. bhenselmann
    Posted 4 years ago #

    Thanks Ipstenu for the hint with switch_to_blog(). I didn´t revognized this funktion up to now.
    I´ve found an other way in the meantime, which do it all together: get_blog_post($blogID,$pageID).

  5. Zambrano Sergio
    Posted 3 years ago #

    YES!! bhenselmann!! You answered all my questions!!

    Do you think of many problems (if less than 3, I'll do it!) by replacing the "get_page()" functions with "get_blog_post()" instead?

    -and adding my main site's ID as the first parameter -

    That'd make my day perfect until wp provides "mirror" or "alias" pages to get some pages to be shared across the network.


  6. Zambrano Sergio
    Posted 3 years ago #

    Ohh… I jumped the gun :(

    I know the title of the page I want to access, but the ID could be different for each site, and in order to get_page_by_title() I need to switch the blog first. Exactly what I though I could avoid.

    Anyway, you answered something nobody answered, a function right inside WordPress!! :)

    Anyway, I'd be cool this plugin get that parameter included for new-coming multisites.

  7. dains
    Posted 3 years ago #

    Hi, I'm researching something along the same lines - show some specific blog posts from each blog in a view on the main blog. Thanks @bhenselmann for that code, looks like it will do the trick without a bunch of coding. Nice one!

  8. Curtiss Grymala
    Posted 3 years ago #

    @SergioZambrano - You don't necessarily have to switch_to_blog(). You could use $wpdb->set_blog_id() instead; and pull the post info directly out of the database.

    The code might look something like:

    function get_page_by_title_from_blog( $post_title, $blog_id=0 ) {
      if( 0 == $blog_id || !is_numeric( $blog_id ) )
        return get_page_by_title( $post_title );
      global $wpdb;
      $org_blog = $wpdb->set_blog_id( $blog_id );
      $page = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE post_title=%s AND post_type=%s", $post_title, 'page' ) );
      $wpdb->set_blog_id( $org_blog );
      return $page;
  9. SocialBlogsite
    Posted 3 years ago #

    @Curtiss Grymala - Yes, your code is exactly what I try to avoid. I don'n like to ping the database myself, where I have functions for that. If I learned the database structure and where each piece of info is used (and how the DB will change in the future updates to avoid soon-to-be-deprecated data) I wouldn't have any more kb spare in my head to remember wp functions I need for layouts! hehe.

    When I feel more comfortable with database messing (which I see easy enough already) I'll give it a shot :)

    So far I fixed it with threewp broadcast plugin. Badly tagged but solved all my needs.

    but this piece of code from Bhenselmann was the solution to this post
    Thanks a lot for your help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Improved Include Page
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic