WP Discourse: Modify existing comments template

Hi there,

I use a custom comment template on my WordPress installation. Therefore I do not want to enable the “Commenting” feature provided in WP Discourse.

What I would like to achieve now is an extension to my existing template:

  • How can I query if a post has already been published in Discourse?
  • If the check returns “true” (published), I would like to simply include a link to the post in the Discourse forum

How can I achieve this?

1 Like

Hey @OrkoGrayskull :slight_smile:

If a post is published to Discourse using the WP Discourse plugin the permalink to the post is saved in the wp post meta field discourse_permalink. So you just need to show that in your theme where you want the link to appear. Something like this:

<li><a href="<?php get_post_meta(get_the_ID(), 'discourse_permalink', true); ?>">Discuss this on our form</a></li>
1 Like

Thanks @angus.

I got it working! :slight_smile:


if ( get_post_meta( get_the_ID(), 'discourse_permalink', true ) ) {
   $discourse_permalink = get_post_meta( $post->ID, 'discourse_permalink', true );       
   echo '<a href="' . esc_url( $discourse_permalink ) . '" title="Forum">Comment on our forum</a>';
}
1 Like