# WordPress Hook to Change Default Publishing Discourse Category per Post Type

**URL:** <https://meta.discourse.org/t/wordpress-hook-to-change-default-publishing-discourse-category-per-post-type/252383>\
**Category:** WordPress\
**Created:** [January 20, 2023, 5:06am UTC](https://meta.discourse.org/t/wordpress-hook-to-change-default-publishing-discourse-category-per-post-type/252383 "2023-01-20T05:06:29Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

The discussion revolves around finding a WordPress hook to change the default Discourse category based on the post type. [TEKFused](/t/-/252383/1) is looking to publish posts of different types to specific categories or subcategories. [simon](/t/-/252383/2) suggests using the `wp_discourse_publish_categories` filter hook, which allows filtering categories by custom post type. [TEKFused](/t/-/252383/3) plans to test this solution and report back with any issues.

<div class="post-metadata">

**Author:** ![TEKFused](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tekfused/32/289343_2.png) [@TEKFused](https://meta.discourse.org/u/TEKFused)\
**Post date:** [January 20, 2023, 5:06am UTC](https://meta.discourse.org/t/wordpress-hook-to-change-default-publishing-discourse-category-per-post-type/252383/1 "2023-01-20T05:06:29Z")

</div>

Hello!

I’d like to change the “Default Discourse Category” dependent on the post’s post type. Is there a WordPress hook I can use to accomplish this?

So basically, if a post is post type a, it would post to category 1, and if a post is post type b, it would post to category 2.

I’d also like to be able to post to subcategories if that matters in the code.

Thank you very much!

Jake

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [January 20, 2023, 6:12am UTC](https://meta.discourse.org/t/wordpress-hook-to-change-default-publishing-discourse-category-per-post-type/252383/2 "2023-01-20T06:12:41Z")

</div>

> [@TEKFused](#):
>
> I’d like to change the “Default Discourse Category” dependent on the post’s post type. Is there a WordPress hook I can use to accomplish this?

There is a `wp_discourse_publish_categories` filter hook that I think will work for this. Some details about it are here: [WP Discourse plugin tips and tricks](https://meta.discourse.org/t/wp-discourse-plugin-tips-and-tricks/50757#filtering-the-available-categories-for-a-custom-post-type). In the example code, I set it so that two categories were available for a custom post type. I think for your case all you will need to do is just make a single category available per custom post type. You will need to test this out.

> [@TEKFused](#):
>
> I’d also like to be able to post to subcategories if that matters in the code.

As long as the “Display Subcategories” option is enabled, you will be able to use subcategories. That option is found on the [WP Discourse](https://github.com/discourse/wp-discourse) plugin’s Publishing Settings tab.

---

<div class="post-metadata">

**Author:** ![TEKFused](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tekfused/32/289343_2.png) [@TEKFused](https://meta.discourse.org/u/TEKFused)\
**Post date:** [January 20, 2023, 6:26am UTC](https://meta.discourse.org/t/wordpress-hook-to-change-default-publishing-discourse-category-per-post-type/252383/3 "2023-01-20T06:26:36Z")

</div>

Thanks very much! I’ll take a look and will let you know if I bump into any issues.
