db 연동 문의
본문
현재 워드프레스 멀티사이트를 이용중인데,
각 멀티사이트별로 그누커머스 모든 db가 따로 되더라구요
하나로 통일시키고 싶은데,
어디를 건드려야 할까요~?
답변 1
/gnucommerce/lib/gc_board_var.class.php
에서
이 항목을 찾아서
public function get_table_array($tables=array()) {
global $wpdb;
$this->db_tables = $tables = wp_parse_args( $tables, array(
'board_table' => $wpdb->prefix.'g5_board',
'meta_table' => $wpdb->prefix.'g5_writemeta',
'write_table' => $wpdb->prefix.'g5_write',
'comment_table' => $wpdb->prefix.'g5_write_comment',
'relation_table' => $wpdb->prefix.'g5_term_relationships',
'taxonomy_table' => $wpdb->prefix.'g5_term_taxonomy',
'point_table' => $wpdb->prefix.'g5_point',
'scrap_table' => $wpdb->prefix.'g5_scrap',
'board_good_table' => $wpdb->prefix.'g5_board_good',
));
return $tables;
}
아래와 같이 고쳐 주세요. ( 고친 부분은 다음 버젼에 업데이트 하겠습니다. )
public function get_table_array($tables=array()) {
global $wpdb;
$board_table = apply_filters('gcboard_default_table', array(
'board_table' => $wpdb->prefix.'g5_board',
'meta_table' => $wpdb->prefix.'g5_writemeta',
'write_table' => $wpdb->prefix.'g5_write',
'comment_table' => $wpdb->prefix.'g5_write_comment',
'relation_table' => $wpdb->prefix.'g5_term_relationships',
'taxonomy_table' => $wpdb->prefix.'g5_term_taxonomy',
'point_table' => $wpdb->prefix.'g5_point',
'scrap_table' => $wpdb->prefix.'g5_scrap',
'board_good_table' => $wpdb->prefix.'g5_board_good',
));
$this->db_tables = $tables = wp_parse_args($tables, $board_table);
return $tables;
}
그리고 항상 실행되는 파일에서 아래와 같이 filter를 걸으시면 됩니다.
//prefix 변경 이라고 주석친 아래에 replace할 string 을 지정해 주시면 됩니다.
add_filter('gc_default_table', 'gc_custom_set_table_names', 99);
if( !function_exists('gc_custom_set_table_names') ){
function gc_custom_set_table_names($tables){ //쇼핑몰 테이블
global $wpdb;
$return_tables = array();
foreach($tables as $key=>$name){
//prefix 변경
$return_tables[$key] = str_replace($wpdb->prefix, 'wp_', $name);
}
return $return_tables;
}
}
add_filter('gcboard_default_table', 'gcboard_custom_table_names', 99);
if( !function_exists('gcboard_custom_table_names') ){
function gcboard_custom_table_names($tables){ //게시판 테이블
global $wpdb;
$return_tables = array();
foreach($tables as $key=>$name){
//prefix 변경
$return_tables[$key] = str_replace($wpdb->prefix, 'wp_', $name);
}
return $return_tables;
}
}