最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

multisite - How to share same post to multiple site in wordpress?

programmeradmin0浏览0评论

We are developing WordPress with multiple site. We need to share some posts to more than one site. We need to save post in more than one sites with a single click.

I have searched in Google, but I can't get any tutorial for that.

We are developing WordPress with multiple site. We need to share some posts to more than one site. We need to save post in more than one sites with a single click.

I have searched in Google, but I can't get any tutorial for that.

Share Improve this question edited Jul 13, 2016 at 19:00 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Jul 13, 2016 at 18:35 muthupandimuthupandi 211 gold badge1 silver badge2 bronze badges 3
  • A bit off-topic but wouldn't that be considered as duplicate content and bad for SEO? – Sledge Hammer Commented Jul 13, 2016 at 18:40
  • 2 @SledgeHammer No that's syndicated content an not necessarily bad for SEO – cjbj Commented Jul 13, 2016 at 18:49
  • "Multiple site" doesn't mean a multisite network, right? For anyone who is still looking for a similar solution, I'd recommend to check this plugin out rudrastyh/plugins/simple-wordpress-crossposting – Misha Rudrastyh Commented Jun 1, 2024 at 11:07
Add a comment  | 

2 Answers 2

Reset to default 2

You can use the function switch_to_blog() for this

$other_id = 1234 // the id of the other blog to save the post to
switch_to_blog($other_id);
$my_post = array(
  'post_title'    => $post_title,
  'post_content'  => $post_content,
  'post_status'   => 'publish',
  'post_author'   => $post_author,
  );

// Insert the post into the database
wp_insert_post( $my_post );

restore_current_blog();

There is a pitfall if you execute this code on the save_post hook, because wp_insert_post also calls save_post and you end up in an infinite loop. This post on Stack Overflow gives a solution for that.

Author of Broadcast here.

Seeing as I have quite a bit of experience with multiposting, and all it's associated problems, I'd suggest you let an experienced plugin take care of post sharing.

Using the API you can broadcast out the post to however many networked blogs you want. It will take care of all of the copying of attachments (yeah, attachments have different URLs and IDs on each blog) for you.

Here's how to broadcast post 123 to several blogs:

ThreeWP_Broadcast()->api()->broadcast_children( 123, [ 10, 11, 12 ] );

The above will also link the posts together, so when you update post 123, all of the children will be updated also.

发布评论

评论列表(0)

  1. 暂无评论