# I would like to automatically sync WP posts with existing Discourse topics if they have the same name. How to get a topic by title?

**URL:** https://meta.discourse.org/t/i-would-like-to-automatically-sync-wp-posts-with-existing-discourse-topics-if-they-have-the-same-name-how-to-get-a-topic-by-title/90753
**Category:** WordPress
**Created:** [25 juni 2018 om 23:52 UTC](https://meta.discourse.org/t/i-would-like-to-automatically-sync-wp-posts-with-existing-discourse-topics-if-they-have-the-same-name-how-to-get-a-topic-by-title/90753 "2018-06-25T23:52:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [25 juni 2018 om 23:52 UTC](https://meta.discourse.org/t/i-would-like-to-automatically-sync-wp-posts-with-existing-discourse-topics-if-they-have-the-same-name-how-to-get-a-topic-by-title/90753/1 "2018-06-25T23:52:47Z")

</div>

Hi.  
I have ~200 articles on my WP.  
I also have topics with the same name on my Discourse, from a phpbb import.

The phpbb topics were created when new articles were published in our previous CMS.

I’d like to sync all these old WP posts to these Discourse topics.

How would you do that? Not specifically how to call the sync, but rather how to get the topics from their title, while minimizing the risk of mismatches? I’m pretty confident that the WP posts and Discourse topic have the exact same title.

Should I use the Discourse search, get the first result and compare the title?

---

<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: [26 juni 2018 om 00:12 UTC](https://meta.discourse.org/t/i-would-like-to-automatically-sync-wp-posts-with-existing-discourse-topics-if-they-have-the-same-name-how-to-get-a-topic-by-title/90753/2 "2018-06-26T00:12:57Z")

</div>

You could do it manually with this:

> [@Link an existing topic to a WordPress post](https://meta.discourse.org/t/link-an-existing-topic-to-a-wordpress-post/88482):
>
> The [WP Discourse](https://github.com/discourse/wp-discourse) plugin lets you link an existing Discourse topic to a WordPress post. To do this, go to the post’s edit page on WordPress and select Link to Existing Topic from the Discourse meta box. In the Topic URL field, enter the URL of a topic from your forum. You can get the URL from your browser’s address bar, or from any of the topic’s share links. (Note: you need to be on at least version 1.6.5 of the plugin to be able to use the share link URLs.) Click the WordPress Publ…

Or write a script that calls a function similar to this:

> <https://github.com/discourse/wp-discourse/blob/main/admin/meta-box.php#L379>

Since you only have the topic titles, and not the topic ids, I think you’ll need to make a request to the Discourse topic without the id and get the redirect that’s returned from Discourse. Something like `curl http://localhost:3000/t/your-topic-without-the-id -s -L -I -o /dev/null -w '%{url_effective}' `

---

<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: [26 juli 2018 om 00:13 UTC](https://meta.discourse.org/t/i-would-like-to-automatically-sync-wp-posts-with-existing-discourse-topics-if-they-have-the-same-name-how-to-get-a-topic-by-title/90753/3 "2018-07-26T00:13:11Z")

</div>

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