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

How to post same content on multisite?

programmeradmin4浏览0评论

Trying to accomplish the following. Any help / advice is greatly appreciated. 1) I have multiple site on subdirectory using wp multisite names (e.g., /, /, /). 2) I need post each domain to display the same content & images (featured image) BUT 3) Show a different Wordpress Theme, Plugins & Plugin Configuration. etc

Trying to accomplish the following. Any help / advice is greatly appreciated. 1) I have multiple site on subdirectory using wp multisite names (e.g., https://noorshaad/uae/, https://noorshaad/us/, https://noorshaad/uk/). 2) I need post each domain to display the same content & images (featured image) BUT 3) Show a different Wordpress Theme, Plugins & Plugin Configuration. etc

Share Improve this question asked Oct 12, 2019 at 17:47 Shaad AminShaad Amin 131 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Here's a concept code (i.e. not tested, requires tweaking) that you could maybe use. With this example a post you create would get cloned to other subsites in your network.

function copy_content( $post_id, $post, $update ) {

  // check for revision, autosave, etc.

  $args = array(
    'site__not_in' => array( get_current_blog_id() ),
  );
  $sites = get_sites( $args );

  $post = $post->to_array(); // post object to array as insert/update functions require array

  foreach ($sites as $site) {
    switch_to_blog( $site->blog_id );

    if ( $update ) {
      wp_update_post( $post );
    } else {
      wp_insert_post( $post );
    }

    restore_current_blog();
  }

}

add_action( 'save_post', 'copy_content', 10, 3 );

Another option could be to use pre_get_posts on your subsites to pull posts from one main posts site. This has been covered for example here, How would I use pre_get_posts to query another site for posts in my multisite network?

发布评论

评论列表(0)

  1. 暂无评论