For Wordpress projects, it is necessary to create a test environment that uses the same DB as the production environment that is being operated. Wordpress environment was created on two servers with exactly the same file structure.

Developing and operating WordPress with CPI's SmartRelease ,

Inwp-config.phpin test server
To override the siteurl and home WP option variables in the database
The following code has been added.

define ('WP_HOME', 'http: //staging-example.com');
define ('WP_SITEURL', 'http: //staging-example.com');

However, even if you access http://staging-example.com, you will be redirected to the production URL.

You can accesshttp://staging-example.com/wp-adminwithout being redirected and it works fine.

How can I change the siteurl and home only in the test environment while keeping the common DB?

In general, it has been described thatdefine ('WP_HOME' ...only works well (the test environment URL can be accessed), but
What are some of the possibilities that will not work this time?

Trying 1. Rewrite DB

The description of this wp-config.php

update_option ('siteurl', 'http: //staging-example.com');
update_option ('home', 'http: //staging-example.com');
When the data in the production DB is updated instead of

, the data in the DB is safely rewritten.
You can access http://staging-example.com (although the production URL will be redirected this time).

2. Overrideget_site_url ()

Usingpre_option _ {$option}of API,

add_filter ('pre_option_siteurl', 'change_get_option_siteurl');
function change_get_option_siteurl ($option) {
  if (defined ('WP_SITEURL')) {
    return WP_SITEURL;
  return false;

Was added tothemename/functions.phpon the test server, but there was no change.

  • Answer # 1


    for filter hooks