# Effect of changing the WordPress site URL

**URL:** https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275
**Category:** WordPress
**Created:** [2017 年9 月 18 日 14:05 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275 "2017-09-18T14:05:20Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 14:05 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/1 "2017-09-18T14:05:20Z")

</div>

Recently we changed the DNS on our WordPress site to use [www.ourdomain.com](http://www.ourdomain.com) instead of [ourdomain.com](http://ourdomain.com). There is a redirect in place so that old links should go to the new www version, but it actually broke the “Show Full Post” links on the Discourse site posts. I’m guessing that generating a new API key and plugging that into the plugin settings would fix all posts going forward, but I’m worried about what will happen to old posts on discourse. Will they remain on the discourse site? If so, will they be updated with the new www version? Thanks!

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 18 日 15:25 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/2 "2017-09-18T15:25:05Z")

</div>

Generating a new API key won’t break anything, but it won’t solve the problem with the old posts on your site.

What happens if you try and republish one of the old WordPress posts by clicking the Update button on the WordPress post edit screen?

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 15:28 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/3 "2017-09-18T15:28:44Z")

</div>

I get an error in WordPress - “There has been an error publishing this post to Discourse.”

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 15:48 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/4 "2017-09-18T15:48:00Z")

</div>

fwiw I regenerated the API key and am still getting the same error

---

<div class="post-metadata">

### 作者： ![wesochuck](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wesochuck/32/108706_2.png) [@wesochuck](https://meta.discourse.org/u/wesochuck)
#### 发布日期： [2017 年9 月 18 日 15:52 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/5 "2017-09-18T15:52:06Z")

</div>

> [@jenkma02](#):
>
> Recently we changed the DNS on our WordPress site to use [www.ourdomain.com](http://www.ourdomain.com) instead of [ourdomain.com](http://ourdomain.com).

Was Discourse also running under the [outdomain.com](http://outdomain.com) domain name (installed alongside Wordpress)? If so, you might want to review: [Change the domain name or rename your Discourse](https://meta.discourse.org/t/change-the-domain-name-or-rename-my-discourse/16098)

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 15:56 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/6 "2017-09-18T15:56:17Z")

</div>

The discourse install is running at [discuss.ourdomain.com](http://discuss.ourdomain.com). I’m not sure what that means for www vs no www though

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 15:58 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/7 "2017-09-18T15:58:34Z")

</div>

I also just tried posting a new post and it published correctly to discourse. It seems like regenerating the API key took care of this. Another post that we published on wordpress since we switched our dns did not get published on discourse. Updating this existing post still results in an error.

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 18 日 16:24 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/8 "2017-09-18T16:24:01Z")

</div>

Does the post still exist on your Discourse forum?

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 16:29 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/9 "2017-09-18T16:29:07Z")

</div>

Sorry, which post are you talking about? The new one that I published on WordPress after regenerating my API key was successfully posted to Discourse. Any posts that were published on WordPress following the DNS switch but _before_ the API key regeneration were not successfully posted to Discourse and updating them does not publish them to Discourse.

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 16:52 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/10 "2017-09-18T16:52:39Z")

</div>

just realized which reply you were referring to. Yes any posts that I try to update that I’m getting an error on (with the exception of the “in between one” that happened during the time after DNS switch but before API key regeneration) still exist on the discourse forum.

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 18 日 19:38 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/11 "2017-09-18T19:38:39Z")

</div>

I’d never considered the scenario where the WordPress domain name is changed. There are a few things that could be going wrong. I’ll look at it some more and see if it’s something that can be made to work.

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 18 日 19:50 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/12 "2017-09-18T19:50:40Z")

</div>

sounds good, thanks for your help!

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 19 日 01:40 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/13 "2017-09-19T01:40:00Z")

</div>

I haven’t yet looked at why there was a problem publishing posts after the WordPress site URL changed. My guess about what’s happening with the posts that you are not able to republish to Discourse is that WordPress thinks the post already exists on Discourse and is trying to update a post instead of to create a new Discourse topic.

You could check that by running this MYSQL query on your WordPress database. Substitute the WordPress post\_id of a post you are not able to republish for `$post_id`.

`SELECT * FROM wp_postmeta WHERE post_id = $post_id;`

If you are seeing meta\_key values for ‘discourse\_post\_id’, ‘discourse\_topic\_id’, and ‘discourse\_permalink’, that will be the problem. If that is the case, running the following query should allow you to republish the post. Substitute the WordPress post\_id for $post\_id.

`DELETE FROM wp_postmeta WHERE post_id = $post_id AND meta_key IN ('discourse_post_id', 'discourse_topic_id', 'discourse_permalink');`

If you like, try this on one post that you can’t republish and that you are sure doesn’t exist on your Discourse forum.

I’m going to make a change to the wp-discourse plugin so that it automatically unlinks posts from Discourse if a 404 (not-found) response is returned from Discourse.

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 19 日 14:37 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/14 "2017-09-19T14:37:02Z")

</div>

So once I regenerated the API token, new posts are publishing just fine to Discourse. It’s the old topics inside discourse that aren’t working when you click the “Show Full Post” button. There is a redirect on the old [ourdomain.com](http://ourdomain.com) to [www.ourdomain.com](http://www.ourdomain.com), but it’s like discourse isn’t recognizing it. Is there a way to change the links somewhere in discourse to point to [www.ourdomain.com](http://www.ourdomain.com)?

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 19 日 15:41 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/15 "2017-09-19T15:41:35Z")

</div>

> [@jenkma02](#):
>
> It’s the old topics inside discourse that aren’t working when you click the “Show Full Post” button

That makes sense. When you try to republish those posts from WordPress, do you get an error message on WordPress?

> [@jenkma02](#):
>
> Is there a way to change the links somewhere in discourse to point to [www.ourdomain.com](http://www.ourdomain.com)?

The links are stored on Discourse. They can probably be rewritten from the rails console. I’m not sure if there’s any other way to do it.

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 20 日 18:02 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/16 "2017-09-20T18:02:36Z")

</div>

> [@jenkma02](#):
>
> There is a redirect in place so that old links should go to the new www version, but it actually broke the “Show Full Post” links on the Discourse site posts.

From looking at the Discourse code, it seems that Discourse should be following the redirect to fetch the full post content. I’m not setup to test this right now.

If that can’t be made to work, rewriting the TopicEmbed embed\_urls that match your old WordPress URL can be done through the rails console. It’s fairly straightforward to do it.

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 21 日 15:54 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/17 "2017-09-21T15:54:14Z")

</div>

I tried changing the links manually to the www versions and it’s actually still broken. It must be pulling that link from somewhere else?

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 21 日 18:20 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/18 "2017-09-21T18:20:22Z")

</div>

> [@jenkma02](#):
>
> I tried changing the links manually to the www versions

If you open the Discourse rails console and enter this, substituting the Discourse topic\_id of a broken embed for `your_topic_id`, are you seeing the correct URL?

`> TopicEmbed.find_by(topic_id: your_topic_id).embed_url`

---

<div class="post-metadata">

### 作者： ![jenkma02](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jenkma02/32/120687_2.png) [@jenkma02](https://meta.discourse.org/u/jenkma02)
#### 发布日期： [2017 年9 月 21 日 19:24 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/19 "2017-09-21T19:24:03Z")

</div>

Maybe a dumb question, but you guys host for us. Do I still have access to this?

---

<div class="post-metadata">

### 作者： ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### 发布日期： [2017 年9 月 21 日 20:16 UTC](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275/20 "2017-09-21T20:16:43Z")

</div>

I don’t know, but the Discourse team have access to it. Maybe someone can take a look.

[下一页](https://meta.discourse.org/t/effect-of-changing-the-wordpress-site-url/70275.md?page=2)
