# Possible to publish from Wordpress only a specified category?

**URL:** https://meta.discourse.org/t/possible-to-publish-from-wordpress-only-a-specified-category/246437
**Category:** WordPress
**Created:** [November 22, 2022, 4:43pm UTC](https://meta.discourse.org/t/possible-to-publish-from-wordpress-only-a-specified-category/246437 "2022-11-22T16:43:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![vanclute](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vanclute/32/282155_2.png) [@vanclute](https://meta.discourse.org/u/vanclute)
#### Post date: [November 22, 2022, 4:43pm UTC](https://meta.discourse.org/t/possible-to-publish-from-wordpress-only-a-specified-category/246437/1 "2022-11-22T16:43:20Z")

</div>

We have integrated Discourse into our Wordpress site, and posting manually works. I would however like to set up auto-posting to Discourse of only posts that fall into a specific category. I see we can exclude by tag, but that doesn’t help in this use-case. I would like to include by category. Is this possible and if not, could it be added as a feature? Seems like it would be an awfully useful/important option and honestly I was quite surprised to find it doesn’t appear to be there already. Thanks.

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [November 22, 2022, 5:22pm UTC](https://meta.discourse.org/t/possible-to-publish-from-wordpress-only-a-specified-category/246437/2 "2022-11-22T17:22:27Z")

</div>

Hey @vanclute,

You can use the `wpdc_publish_after_save` filter to achieve this. In your Wordpress `functions.php` file add the following:

```php
function publish_to_discourse( $force_publish, $post_id, $post ) {
  return has_term( TERM, TAXONOMY, $post );
}
add_filter( 'wpdc_publish_after_save', 'publish_to_discourse', 10, 3 );

```

You’ll need to replace TERM and TAXONOMY with whatever you’re using for “categories” in Wordpress. Note that TERM can be an array, e.g.

```php
array( 'category name 1', 'category name 2')

```

### Example

```php
function publish_to_discourse( $force_publish, $post_id, $post ) {
  return has_term( array( 'news', 'blog' ), 'category', $post );
}
add_filter( 'wpdc_publish_after_save', 'publish_to_discourse', 10, 3 );

```

---

<div class="post-metadata">

### Author: ![vanclute](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vanclute/32/282155_2.png) [@vanclute](https://meta.discourse.org/u/vanclute)
#### Post date: [November 22, 2022, 5:44pm UTC](https://meta.discourse.org/t/possible-to-publish-from-wordpress-only-a-specified-category/246437/3 "2022-11-22T17:44:56Z")

</div>

Thanks. Really would prefer to not have to modify any WP files but appreciate the pointers.

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [November 22, 2022, 6:42pm UTC](https://meta.discourse.org/t/possible-to-publish-from-wordpress-only-a-specified-category/246437/4 "2022-11-22T18:42:59Z")

</div>

There is no need to modify anything 😉 Do it as it should do…

Install Code Snippet or similar and do that through it (sure, you can do it as a separate plugin if you prefer that; no differences). Totally same thing than installing a theme component or a plugin to Discourse.

And use functions.php of _child theme_ only when modification is theme dependent. It is not the case this time.
