Yes, you’re on the right track. In broad strokes, what you need to do is
Retrieve the topic details from discourse (unless you have these already)
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.
@Angus, thanks for your response. I’m in PHP kindergarten, so if you’re planning to work on this, I’ll wait.
Also, I’m getting a repeatable error with the WP plugin. Don’t know if you want a separate post or GitHub issue, but here’s what’s happening:
When I open a WP post that is linked to a forum topic, the link does not show in the Discourse block. It looks like there is no link.
Conditions:
This occurs whether the link was created by publishing a ‘New Topic’, or by ‘Link to Existing Topic’
My WP posts are CPTs.
My Commenting is set to “Display a link to the comments”
Other than that, there’s nothing special about my installation
Confirmation:
I can confirm that links that don’t show in the Discourse block do exist by seeing them in my Admin columns, and because I can click on the frontend link and go to the forum post.
I’ll be happy to help with more information or testing.
Yes. I should have mentioned, everything works at first: I can publish to a new topic, or link to an existing topic and the links work both ways …except
If I later re-edit a post on WP, the Discourse block looks like nothing is linked, even though my WP frontend link still goes to the correct forum topic, and the link in the forum topic still goes to the correct WP post.
So the problem only exists in the WP Discourse block while re-editing a post.
Do you see any errors in your browser web inspector console?
If you do a full refresh on the page while viewing the editor, what happens?
It sounds like there’s a javascript issue. This could be caused by various things, including other plugins or a browser extension. We need to narrow it down a bit more if possible.
First the Discourse block shows Publishing Options / Pin Topic and Publish to Discourse sections. Then the Category section pops in. Does not show existing links.
I turned off every plugin except WP-Discourse, CPT and ACF then tried it with a Brave browser and Edge browser, both with no extensions and shields off. Still can’t see existing links in the Discourse block.
I’m running a test between regular posts and CPT posts. I’ll let you know the results.