Tag posts that are published from WordPress to Discourse

AI-generated summary

Tagging Posts Published from WordPress to Discourse

The WP Discourse plugin allows users to tag posts when publishing from WordPress to Discourse. Tags can be added individually or as a comma-separated list in the Discourse meta box Advanced Options. Spaces in tag names are converted to hyphens. The maximum number of tags is set by the ‘Maximum Number of Tags’ option, defaulting to 5 if left empty.

Initially, there was no hook to automatically add tags to specific custom post types. simon and angus confirmed that this feature was not available but would be added in a future release.

After two years, Fma965 inquired about the status of this feature. angus acknowledged the delay but promised to include it in the next release. However, angus later clarified that the next release did not include this feature.

A workaround was provided by angus using the wpc_publish_body filter to add tags to specific post types. The 2.4.5 update made this process easier by adding the post_id parameter to the filter.

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 Likes

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

1 Like

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 Likes

Sorry to bump such a old post but did this get added? i’ve tried looking through the source code but couldn’t find anything.

2 Likes

We haven’t yet added that hook. I’ll add it into the next release :+1:

2 Likes

It’s been 2 years :open_mouth: it should have been added ages ago :laughing:

Nah just kidding, thanks in advance :slight_smile: :+1:

1 Like

Hey, i see a new release has been created, was this added?

No, that release concerned another, specific, issue. I’ll make sure it’s in the next one.

You can use the wpc_publish_body filter to achieve this, e.g.

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 adds post_id as a param to the filter to make the specific case of adding tags to posts of certain types easier.

2 Likes