0
votes

I am developing a WordPress site to show posts from different WordPress installation (Sub domains), this new WordPress installation would be the main website.

Each source website is a sub-domain like news.example.com, sports.example.com, cars.example.com, business.example.com etc.

What i want to do is to show recent posts from above sub-domains to main website www.example.com.

Whether i can use some thing like MULTI-SITE WordPress installation, without affecting sub-domains.

I am good in php but new to WordPress.

I am also thinking to use plugin feedWordPress (this help in reading posts from other WordPress installation feeds and store in local installation), to pull posts from sub-domains to the main site database.

Please suggest the best suitable method.

1

1 Answers

0
votes

1) You can use RSS FEED

$feed = simplexml_load_file('http://your-sub-domain.com/feed/');
$posts = $feed->channel;
foreach ( $posts->item as $post  ) {
    echo '<a href="'.$post->link.'">'.$post->title.'</a>';
}

2) or use WP API

$posts = json_decode(file_get_contents('http://your-sub-domain.com/wp-json/wp/v2/posts?filter[posts_per_page]=6&filter[orderby]=date'));
foreach ( $posts as $post ) {
    echo '<a href="'.$post->link.'">'.$post->title->rendered.'</a>';
}