Automatically Select Topic Category Based on Post Category?

You can do this with the wpdc_publish_post_category filter. It’d be something like (untested example code, but may work out of the box):

function wpdc_change_post_category( $category, $post_id ) {
  $wp_category_name = get_the_category( $post_id )[0]->name
  $discourse_categories = WPDiscourse\Utilities\Utilities::get_discourse_categories();
  $discourse_category = array_search( $wp_category_name, array_column( $discourse_categories, 'name' ));
  return $discourse_category['id'];
}
add_filter( 'wpdc_publish_post_category', 'wpdc_change_post_category' );

Then, no matter what category you selected, the post would always be posted to a category with a name that matches the name of the Wordpress post category. Make sure those names match exactly though otherwise it won’t work.

Officially supporting this as a feature would be fraught with difficulty as it would rely on users maintaining lists of categories with the exact same names, assume that the category models between the two platforms remain the same and have to deal with the fact that Wordpress’ taxonomy system is inherently mutable (i.e. it won’t be the same on every Wordpress the plugin is installed on)

1 Like