Effect of changing the WordPress site URL


(Katie Jenkins) #1

Recently we changed the DNS on our WordPress site to use www.ourdomain.com instead of 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!


(Simon Cossar) #2

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?


(Katie Jenkins) #3

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


(Katie Jenkins) #4

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


(Wes Osborn) #5

Was Discourse also running under the outdomain.com domain name (installed alongside Wordpress)? If so, you might want to review: Change the domain name or rename my Discourse?


(Katie Jenkins) #6

The discourse install is running at discuss.ourdomain.com. I’m not sure what that means for www vs no www though


(Katie Jenkins) #7

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.


(Simon Cossar) #8

Does the post still exist on your Discourse forum?


(Katie Jenkins) #9

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.


(Katie Jenkins) #10

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.


(Simon Cossar) #11

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.


(Katie Jenkins) #12

sounds good, thanks for your help!


(Simon Cossar) #13

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.


(Katie Jenkins) #14

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 to 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?


(Simon Cossar) #15

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

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.


(Simon Cossar) #16

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.


(Katie Jenkins) #17

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?


(Simon Cossar) #18

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


(Katie Jenkins) #19

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


(Simon Cossar) #20

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