[![Wordpress多站点社区动态中获取自定义文章类型更新](https://pic.salongweb.com/2016/03/wordpress-mu-buddypress.jpg)](https://pic.salongweb.com/2016/03/wordpress-mu-buddypress.jpg "Wordpress多站点社区动态中获取自定义文章类型更新")萨龙网络使用Buddypress社区已经很长一段时间，在社区首页动态中可能获取整个网站的最新文章、用户注册，用户动态内容，而自定义文章类型的发布动态默认不会显示在社区动态中，所以今天花点时间Google下解决了这个问题。

### 设置自定义文章类型名，再分别输出不一样的内容，product就输出产品，portfolio就输出作品的字样

1. add\_filter ( ‘bp\_blogs\_record\_post\_post\_types’, ‘activity\_publish\_custom\_post\_types’,1,1 );
2. function activity\_publish\_custom\_post\_types( $post\_types ) {
3. $post\_types\[\] = ‘product’;
4. $post\_types\[\] = ‘portfolio’;
5. return $post\_types;
6. }
7. add\_filter( ‘bp\_blogs\_activity\_new\_post\_action’, ‘im\_activity\_content’, 2, 10 );
8. 
9. function im\_activity\_content($activity\_content, $post, $post\_permalink){
10. if( $post-&gt;post\_type == ‘product’ ) {
11. $activity\_content = sprintf( \_\_( ‘%1$s 在站点 %3$s 中发布了一篇新产品 %2$s‘, ‘buddypress’ ), bp\_core\_get\_userlink( (int)$post-&gt;post\_author ), ‘&lt;a href=“‘ . $post\_permalink . ‘”&gt;’ . $post-&gt;post\_title . ‘&lt;/a&gt;’, ‘&lt;a href=“‘ . get\_blog\_option( $blog\_id, ‘home’ ) . ‘”&gt;’ . get\_blog\_option( $blog\_id, ‘blogname’ ) . ‘&lt;/a&gt;’ );
12. }
13. if( $post-&gt;post\_type == ‘portfolio’ ) {
14. $activity\_content = sprintf( \_\_( ‘%1$s 在站点 %3$s 中撰写了一篇新作品 %2$s‘, ‘buddypress’ ), bp\_core\_get\_userlink( (int)$post-&gt;post\_author ), ‘&lt;a href=“‘ . $post\_permalink . ‘”&gt;’ . $post-&gt;post\_title . ‘&lt;/a&gt;’, ‘&lt;a href=“‘ . get\_blog\_option( $blog\_id, ‘home’ ) . ‘”&gt;’ . get\_blog\_option( $blog\_id, ‘blogname’ ) . ‘&lt;/a&gt;’ );
15. }
16. return $activity\_content;
17. }

代码来源：Buddypress社区
\[successbox\]这样在发布产品与作品等自定义文章类型的文章时，在社区动态就会获取发布的信息。\[/successbox\]