# WP Discourse: filtri personalizzati per discourse\_replies\_html e discourse\_no\_replies\_html

**URL:** https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306
**Category:** WordPress
**Created:** [11 Gennaio 2019, 6:42pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306 "2019-01-11T18:42:53Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [11 Gennaio 2019, 6:42pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/1 "2019-01-11T18:42:53Z")

</div>

[WP Discourse](https://github.com/discourse/wp-discourse) Version 1.8.2: Instead of my custom filters I’m getting “Comments are not currently available for this post.” inside a div that includes the class “discourse-no-connection-notice.” This is regardless of whether the post is using the Classic or Block Editor. The posts do publish to Discourse.

Thinking with the changes needed to be made to the discourse\_publish\_format\_html filter ([WP Discourse: advanced custom filter for discourse\_publish\_format\_html - #9 by simon](https://meta.discourse.org/t/wp-discourse-advanced-custom-filter-for-discourse-publish-format-html/106059/9)), I changed both my replies functions/filters like so:

```plaintext
function cosmos_custom_discourse_replies( $input, $post_id ) {
    ob_start();
    ?>
    custom output here
    <?php
    $output = ob_get_clean();
    return $output;
}
add_filter( 'discourse_replies_html', 'cosmos_custom_discourse_replies', 10, 2 );

```

Didn’t help. Unlinking and relinking to the existing topic results in an empty div with the class “wpdc-comments-loading” (at least in the context of no replies in my playing with it). Adding a comment on Discourse didn’t populate over to WP, still the same empty div. Removing my custom filters entirely does show default “Start the conversation at \_.” Any tips on how to get my old custom filters working with the newest version?

---

<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: [11 Gennaio 2019, 6:54pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/2 "2019-01-11T18:54:33Z")

</div>

> [@Kayla](#):
>
> Thinking with the changes needed to be made to the discourse\_publish\_format\_html filter ([WP Discourse: advanced custom filter for discourse\_publish\_format\_html](https://meta.discourse.org/t/wp-discourse-advanced-custom-filter-for-discourse-publish-format-html/106059/9)), I changed both my replies functions/filters like so:

I think that’s the problem. The `discourse_replies_html` filter only accepts one argument. Something like this should work:

```plaintext
function cosmos_custom_discourse_replies( $input ) {
    ob_start();
    ?>
    custom output here
    <?php
    $output = ob_get_clean();
    return $output;
}
add_filter( 'discourse_replies_html', 'cosmos_custom_discourse_replies' );

```

You can see all the templates here: [wp-discourse/templates/html-templates.php at main · discourse/wp-discourse · GitHub](https://github.com/discourse/wp-discourse/blob/master/templates/html-templates.php). Look at the call to `apply_filters` at the bottom of each template to see the parameters that are passed to the filter.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [11 Gennaio 2019, 7:48pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/3 "2019-01-11T19:48:58Z")

</div>

> [@simon](#):
>
> ```plaintext
> function cosmos_custom_discourse_replies( $input ) {
> ob_start();
> ?>
> custom output here
> <?php
> $output = ob_get_clean();
> return $output;
> }
> add_filter( 'discourse_replies_html', 'cosmos_custom_discourse_replies' );
> 
> ```

is what I started with. @madrush noticed it before the update to [WP Discourse](https://github.com/discourse/wp-discourse) Version 1.8.2, but I thought maybe it was a related issue the new version would solve. And you’re right, my example modification broke existing posts where the replies/no replies were just fine, and which were restored when I went back to my original custom filters (in use since 2016). So the issue seems reserved to publishing new posts.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [11 Gennaio 2019, 8:05pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/4 "2019-01-11T20:05:34Z")

</div>

Interestingly, if I create the topic on Discourse _first_ , then link a post with that existing topic, the replies/comment area works as expected on WP. If I publish the same post type to a _new_ topic in Discourse, I get the “Comments are not currently available for this post.”

---

<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: [11 Gennaio 2019, 8:26pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/5 "2019-01-11T20:26:04Z")

</div>

> [@Kayla](#):
>
> If I publish the same post type to a _new_ topic in Discourse, I get the “Comments are not currently available for this post.”

Do you know if this is working correctly with regular post types? The ‘Comments are not currently available’ template that you are seeing is only displayed when the `discourse_permalink` post\_metadata is not set for a post.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [11 Gennaio 2019, 8:42pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/6 "2019-01-11T20:42:18Z")

</div>

> [@simon](#):
>
> Do you know if this is working correctly with regular post types?

No, I just tried a brand new WP-native post; using the Block Editor. This is also happening on our ‘event’ CPT that is using the Classic Editor, and which is a post type that was working previously with these filters as well. (Our ‘groups’ CPT is new since updating to Wordpress 5, it has same issue but no pre-existing comparisons.) Previously published-to-Discourse replies/no\_replies seem fine for both regular posts and events, it’s just when trying to publish new content/not yet linked to Discourse.

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [11 Gennaio 2019, 10:03pm UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/7 "2019-01-11T22:03:12Z")

</div>

Now that I’m back to using the original filter, this also works: posting to a new topic, then unlinking the post from that topic, then linking it back to the existing topic that was created when first posting to Discourse. Not an ideal workflow, but it might help the picture of what might be going on.

---

<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: [12 Gennaio 2019, 12:38am UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/8 "2019-01-12T00:38:49Z")

</div>

So far I haven’t been able to reproduce this. From what you’re describing, it seems like there is an error when posts are published to Discourse - when a post is published, a call is made to:

```plaintext
update_post_meta( $post_id, 'discourse_permalink', $options['url'] . '/t/' . $topic_slug . '/' . $topic_id );

```

When comments are displayed, if the `discourse_permalink` metadata isn’t set, the (poorly named) `bad_response_html` template is displayed.

When you unlink and then relink the post to Discourse, the `discourse_permalink` metadata is added through another route, so it makes sense that it works when you do that.

If you are developing this locally, you could try logging errors to a `debug.log` file. See [Debugging in WordPress – Advanced Administration Handbook | Developer.WordPress.org](https://codex.wordpress.org/Debugging_in_WordPress) for details. My guess is that you will see an error when you are publishing posts. Any details you can give about this would be great.

One thing to try would be to comment out all your custom templates, and then add them back one by one. Add back the `discourse_publish_format_html` template last. If you have no custom templates, and publish a post normally, are you still seeing the ‘Comments are not currently available for this post’ message?

---

<div class="post-metadata">

### Author: ![Kayla](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kayla/32/128523_2.png) [@Kayla](https://meta.discourse.org/u/Kayla)
#### Post date: [12 Gennaio 2019, 2:45am UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/9 "2019-01-12T02:45:26Z")

</div>

I went to look at the error logs available in our wpengine account, and I did see some in regards to my template file, but I think it’s from when I did that wonky modification with the `( $input, $post_id )`:

```plaintext
[php7:error] PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function cosmos_custom_discourse_replies(), 1 passed and exactly 2 expected in /nas/content/live/theoryofe/wp-content/mu-plugins/cosmos-discourse-templates.php:9

```

Line 9 is `function cosmos_custom_discourse_replies( $input ) {` , and I got a similar error referring to the line `function cosmos_custom_discourse_no_replies( $input ) {`.

I didn’t see anything more recent than these referring to the templates, so I’ll do some more work as you suggest and see if I can find anything helpful. Thanks!

---

<div class="post-metadata">

### Author: ![madrush](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/madrush/32/119502_2.png) [@madrush](https://meta.discourse.org/u/madrush)
#### Post date: [14 Gennaio 2019, 2:57am UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/10 "2019-01-14T02:57:50Z")

</div>

Thanks for all your help with this issue, @simon. I found the source of the error we were seeing. It was a misconfigured webhook. We recently changed the primary domain of our Wordpress multisite, which means the existing webhook set up on the Discourse end was no longer correct. Once I updated it, I was able to successfully create new posts in Wordpress (including in custom post types), which now properly create and connect to a new topic in Discourse.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [13 Febbraio 2019, 2:57am UTC](https://meta.discourse.org/t/wp-discourse-custom-filters-for-discourse-replies-html-and-discourse-no-replies-html/106306/11 "2019-02-13T02:57:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
