0

So usually I would just do a database search and replace for changing my URL but what I've done now is decided to split my site into two different sites which works great for me because of the way I organized content with pages and posts.

All the pages have links going to posts on the same site. I'm moving all the posts to it's own site on domain #2 and I want those links from the pages on domain #1 to point to domain #2. I don't see any problem doing this except for being able to target only pages and not posts. I'm not sure how to do that since wp_posts contains both pages and posts. If anyone has suggestions those are welcome and solutions are very much appreciated.

Here is what I usually use to change the URLS throughout my content:

update wp_posts set post_content = replace(
post_content, 'old_domain.com',
'new_domain.com');
  • You can try to put WHERE clause in this query. Example try to add : WHERE post_type='page'. post_type field in wp_posts table differentiate between pages and posts. – Rishabh Nov 11 '16 at 11:11
  • Will this work: update wp_posts set post_content where post_type='page' = replace( post_content, 'old_domain.com', 'new_domain.com'); – d.ariel Nov 11 '16 at 12:20
  • OK I figured it out thank you for the suggestion to where the post type. – d.ariel Nov 11 '16 at 15:22
1

This is how I solved the problem in which case I wanted to change all the URLS of my target pattern to the new pattern or URL which only applied to pages and not posts. This is the sql query I ran.

update wp_posts set post_content = replace(
post_content, 'old_domain.com',
'new_domain.com') where post_type='page'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.