V
V
Vladimir Kiper2016-08-09 10:59:33
PHP
Vladimir Kiper, 2016-08-09 10:59:33

How to change the url of one page to another via SQL query?

There was a page site.com.ua/kuhonnye-stoleshnicy it was replaced with a new one with a completely different address site.com.ua/stoleshnici-iskusstvennii-kamen
It is necessary to replace all the links that are on the site from the old address to the new one. The easiest way to do this is through a database query. I'm not really familiar with SQL, so I'm asking for help from professionals. What request to register?
Site on Wordpress.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Kozlov, 2016-08-09
@trampick

By default, WP urls for posts and pages are stored in the wp_posts table in the post_meta field. The value of this field must be unique.
The algorithm by which I would write the script:
1 created a data array with the old url and the new url.
2 Get all posts from the wp_posts table (you only need to take posts with a specific post_type value)
3 Would loop through all posts. I would look at each entry if there is a post_name in the array with the initial data in the cells with the old url. If it is, then update the value of this field to the new url.
Implementation will require global $wpdb, $wpdb->get_results(), $wpdb->update().

K
KeyDoo, 2016-08-12
@KeyDoo

Well, in any case, you need to figure out what is in which table and field.
To replace in SQL, use the REPLACE function
dev.mysql.com/doc/refman/5.7/en/string-functions.h...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question