Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

semsem83 on "i need function that make wordpress use custom tables for old posts"

$
0
0

I have a site with about 24,000 posts and 200 posts daily and the database will get huge soon. So I plan to transfer the old posts to custom tables to reduce the database load. There's no need to show these posts on the site. I just want to keep it for search engines and avoiding sql_calc_found_rows problems. These are the three tables I have created:

wp_posts -> wp_custom_posts

wp_postmeta -> wp_custom_postmeta

wp_term_relationships -> wp_custom_term_relationships

I have transferred old posts to these tables manually using phpMyAdmin and use a function to make WordPress use my custom post table instead of wp_posts if the post does not exists in it:

<?php
function custom_prefix_change($sql) {
    global $wpdb,$wp;
    $prefix = $wpdb->prefix;
    if(is_single()){
        //check if the post exists in the genuine posts table
        $results = $wpdb->get_results($sql,"ARRAY_A");

        if($results[0]['ID']){
            //if exists then return
            return $sql;
        }else{
            //else change the query
            $sql = str_replace("$wpdb->posts","{$wpdb->prefix}custom_posts",$sql);
        }
    }
    //echo $sql;
    return $sql;
}
add_action('posts_request',"custom_prefix_change");
?>

However, my old posts in this case show up with no meta and taxonomies values. because wordpress still use the the default meta and relationships tables not my cutomes tables so i need function(s) to replace the default wp_postmeta and wp_term_relationships with my custom tables i just dont know the hook or filter that i should use ..


Viewing all articles
Browse latest Browse all 5527

Trending Articles