Quick Question about Programmatic Link to Existing Topic

Yes, you’re on the right track. In broad strokes, what you need to do is

  1. Retrieve the topic details from discourse (unless you have these already)
  2. Save the relevant details to the right post meta fields

It’s those post meta fields that you see in that function you linked that create the connection.

I’ve also added this to my WP Discourse dev agenda: to make it easier to do this, i.e. using a single public utility function to achieve this goal. I’ve slotted this in for June.

Also take a look at the existing utility functions in lib/plugin_utilities.php and lib/utilities.php. And the concomitant link_topic method in admin/discourse-sidebar/discourse-sidebar.php.

Let me know how you go.