将从 WordPress 发布到 Discourse 的帖子进行标记

Posts can now be tagged when they are published with the WP Discourse plugin. To tag a post, click on the Discourse meta box Advanced Options link to expand the meta box. Add tags to the Tag input, either one at a time, or as a comma separated list.

Any spaces in tag names will be converted to hyphens. The maximum number of tags is set by the ‘Maximum Number of Tags’ option found on the Publishing Settings tab. The maximum number of tags will default to 5 if the setting is left empty. Tags that are not allowed on Discourse due to Site Setting or category restrictions will be omitted when the post is published to Discourse.

7 个赞

Is there a way to hook into this to prepopulate specific custom post types with specific tags?

1 个赞

The WP DIscourse plugin doesn’t have a hook that can be used to automatically add tags to a post before it gets published to Discourse. I’ll add a hook for that can be used for this and let you know when that has been done.

4 个赞

抱歉打扰了这么老的帖子,但这个功能添加了吗?我试着查看了源代码,但什么也没找到。

2 个赞

我们还没有添加那个钩子。我会在下一个版本中添加它 :+1:

2 个赞

两年了 :open_mouth: 早该添加了 :laughing:

不开玩笑了,提前谢谢 :slight_smile: :+1:

1 个赞

嘿,我看到一个新的版本已创建,这是添加的吗?

不,该版本涉及另一个特定问题。我将确保在下一个版本中包含它。

您可以使用 wpc_publish_body 过滤器来实现此目的,例如:

add_filter(  'wpdc_publish_body', function( $body, $remote_post_type, $post_id ) {
   if ( 'create_post' === $remote_post_type ) {
      $body['tags'] = array( 'tag1', 'tag2' );
   }
   return $body;
}, 10, 3);

2.4.5 版本将 post_id 添加为过滤器的参数,以便更轻松地为特定类型的帖子添加标签。

2 个赞