Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display posts from the other sites in a WordPress multisite setup?

I have a small network of sites setup with WordPress 3.0's multisite feature. I would like to create another site which pulls certain posts from the various other sites to display. This new 'hub' site would seem like its own separate site to the user (with domain mapping), but its content is coming from the posts from the other sites.

How can I get posts from another site in a WordPress multisite setup? Can I query for posts based on the name of the site? The end result needs to be a collection of posts from the different sites sorted by date.

Thanks for your help.

like image 548
JGDev Avatar asked Oct 07 '10 19:10

JGDev


People also ask

How do I separate WordPress multisite?

Simply login to the site you need to split away from the multisite installation, and in the dashboard go to Tools > Export. In the export screen select to export “All content”. This will create an XML file with all of the data from the site needed in order to move it to its own installation.

Can multisite have different themes?

With Multisite, users can choose themes and plugins for individual websites without using the Multiple Themes plugin.


2 Answers

I had the similar issue where I wanted to get posts from one blog and display it on an other I came up with the following solution which you could modify slightly to meet your needs if needed

<?php
global $switched;
switch_to_blog(2); //switched to 2

// Get latest Post
$latest_posts = get_posts('category=-3&numberposts=6&orderby=post_name&order=DSC');
$cnt =0;?> 
<ul>
    <?php foreach($latest_posts as $post) : setup_postdata($post);?>
    <li>
        <a href="<?php echo get_page_link($post->ID); ?>" title="<?php echo $post->post_title; ?>"><?php echo  short_title('...', 7); ?></a>
    </li>                                
    <?php endforeach ; ?>

<?php restore_current_blog(); //switched back to main site ?>

I'm also limiting the amount of words which is being out putted if you do not want this feature simple use

$post->post_title; 

Hope it helps.

like image 72
Oudin Avatar answered Oct 17 '22 23:10

Oudin


This wouldn't be terribly difficult to set up with direct database calls. You can query posts from any site on the install with the $wpdb object. See Displaying Posts Using a Custom Select Query for information on using a custom database query, but keep in mind that instead of selecting from $wpdb->posts you're going to need to access the specific site table you want posts from. On a default Wordpress 3 install, this would be wp_12_posts where 12 is the site id. The id can be found in the wp_blogs table, or by looking at the ID column in the Sites section of the admin menu.

like image 20
bhamrick Avatar answered Oct 18 '22 01:10

bhamrick