How to use if condition to change $table_prefix in wp_config.php

I am testing a very big database (perhaps wp_posts contains hundreds of thousands of rows). As such, the query time, especially the searching query, is extremely long. I’m thinking if there is any other way to split the WP database to multiple tables with different table prefix so that the url structure does not change compared to the original database.

I tried changing $table_prefix in wp_config to wpa_, then i created a sample posts with post name start with a. Then i changed $table_prefix in wp_config to wpb_, then i created a sample posts with post name start with b.

Read More

In the next step, i replace the $table_prefix line with

// if query for post start with a, it will go to wpa_ tables,
// if query for post start with b, it will go to wpb_ tables
$prefix = get_the_title(); 

if ($prefix(0) !== 'a') {

    $table_prefix  = 'wpb_';

} else {

    $table_prefix  = 'wpa_';

}

When i tried openning my domain, i got the error Fatal error: Call to undefined function get_the_title() in /home/todaytra/public_html/1/wp-config.php on line 62

I really need to perform this task, usual WPMU installation generates either subdomains or subfolders and it changes the permalink structure of all posts. I tried searching a lot but cannot find any information about this.

Related posts

Leave a Reply

1 comment

  1. Pam,

    It sounds like you are facing some major challenges, but I would highly recommend not messing with the table prefix. Doing so will lead to a series of problems, which will require hack after hack to remedy leaving you with a substantial mess of a WordPress installation.

    There are some other things you can do to help solve issues with slow queries. While these things are not all necessarily straight forward, they are more worth your time than trying to hack the table prefix.

    1) Make sure that you are on WP 3.4+. There were some nice improvements to standard queries in 3.4 that improve query speed.

    2) For particularly problematic queries, consider setting no_found_rows to true, update_post_term_cache to false, and update_post_meta_cache to false. These can all lead to improved query performance, but you definitely need to invest some time in understanding the repercussions. Read about them in the Codex: http://codex.wordpress.org/Class_Reference/WP_Query

    3) Use a persistent object cache to provide caching of queries. This is definitely a more involved process, but by caching expensive queries to RAM or disk, you can save repeated slow queries.

    4) Install a page cache (WP Super Cache does this well) that will help reduce the number of times the expensive query is called. This does not directly address the query issue; however, it reduces the number of times the query may be called.

    Beyond the first suggestion, I do not consider any of these to be “easy”; however, what you suggest to do would be a gigantic waste in my opinion and your time would be better spent investigating alternative options to addressing slow queries in WordPress. You will learn more about WordPress, scalability issues, and better ways to do things in a standard WordPress way.