I am trying to set different categories for different custom_post_types, the code below selects the correct category in the Wordpress admin. However, on publishing to Discourse, the category isn’t set there (and defaults to uncategorised)…
Maybe I am missing something obvious?
// WP Discourse set CPT forum categories for CPTS
add_filter( 'wp_discourse_publish_categories', 'radhr_filter_categories_policies', 10, 2 );
function radhr_filter_categories( $categories, $post ) {
if ( 'policy' === get_post_type( $post ) ) {
$output = [];
foreach ( $categories as $category ) {
if ( 'Policies' === $category['name']) {
$output[] = $category;
}
}
return $output;
}
elseif ( 'guide' === get_post_type( $post ) ) {
$output = [];
foreach ( $categories as $category ) {
if ( 'Guides' === $category['name']) {
$output[] = $category;
}
}
return $output;
}
elseif ( 'post' === get_post_type( $post ) ) {
$output = [];
foreach ( $categories as $category ) {
if ( 'Blogs' === $category['name']) {
$output[] = $category;
}
}
return $output;
}
return $categories;
}