• Resolved Cody ODell

    (@cody-odell)


    I have a site using multiple blogs. I have a main blog, which I want to include the posts of inside all other blogs made on the site. Is this possible? I made a function to get posts from both blogs, but I ran into a wall when I found out ‘blog_id=’ inside wp_query did not accept an array.

    Anyone know if this is possible?

    I would need this to work with the search, and for the actual posts to use the current blog’s URL.

Viewing 9 replies - 1 through 9 (of 9 total)
  • get_blog_id_from_url()

    that function is part of your answer, i’m sure you can do the rest?

    pass in the name of the blog (taken from url)

    get_blog_id_from_url(“maindomain.com”,”/”.$sitename.”/”)

    note: mutlisite uses extra tables for each new blog
    as in wp_siteid_posts

    so my SQL looks like this:
    SELECT post_content,post_title, guid
    FROM wp_”.$blogID.”_posts
    order by ID desc
    limit 5″;

    Thread Starter Cody ODell

    (@cody-odell)

    <?php
    function getGlobalPostArgs($blog_id, $limit = null, $cat = null){
    
    	global $wpdb;
    
    	$global_posts = array();
    
    	$limit        = (empty($limit))?-1:$limit;
    
    	$domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->blogs} WHERE blog_id=1");
    	$posts  = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE guid like '%".$domain."%'");
    
    	if($blog_id != 1){
    
    		$local_domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->blogs} WHERE blog_id=$blog_id");
    		$local_posts  = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE guid like '%".$domain."%'");
    
    		$posts = array_merge($local_posts, $posts);
    
    	}
    
    	$args = array(
    		'post__in' => $posts,
    		'showposts' => $limit,
    		'order' => 'DESC',
    		'orderby' => 'ID',
    		'cat'=> $cat,
    		'blog_id' => $blog_id
    	);
    
    	return $args;
    }
    ?>

    notice how I can only pass one id into blog_id in the arguments.

    I can successfully get the posts from a specific blog ($posts contains an array of post id’s), but this won’t work with wp_query, will it? I would have to write a custom query, like you said. I am thinking therefore, I would have to rewrite everything that depends on wp_query, which is a lot of stuff. Any way around that?

    This plugin has helped me tons…

    https://www.ads-software.com/extend/plugins/feedwordpress/

    I have a main blog that pulls it’s content from 4 individual blogs via rss – they become actual ‘posts’. Work’s like a charm

    If your template supports widgets, then drag and drop an RSS into your sidebar or footer bar, then refresh your site.

    IF you are using an FTP client ALWAYS make sure you refresh you directory from your host panel.

    I have never had a problem with widgets for my site from doing this.

    Thread Starter Cody ODell

    (@cody-odell)

    Neither of those solutions would allow me to use the native search functionality.. I am now thinking about not using MU and just using categories to organize everything..

    The sitewide tags one pulls all blog posts into one blog, which can then be searched using the default search box.

    Thread Starter Cody ODell

    (@cody-odell)

    The solution to my problem was this plugin: https://www.ads-software.com/extend/plugins/multipost-mu/

    That’s the reverse of what you originally asked. ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to include an external blog's posts?’ is closed to new replies.