안녕하세요
그누커머스 갤러리 스킨 사용중입니다.
여분필드를 wr_10 부터 사용중이고
제목대신 여분필드에 입력한 값을 표시되게 할려고 합니다.
제목부분에 여분필드 wr_10 | wr_11 값이 표시 되게 하고 싶은데 어떻게 해야 할까요?
hook.skin.php 에 메타데이터 불러오고
list.skin.php 에서
<?php echo $v['subject'] ?>
이 값을
<?php$input_posts = get_metadata(GCBOARD_META_TYPE, $v['wr_id'], 'etc_inputs', true ); $wr_10 = isset($input_posts['wr_10']) ? $input_posts['wr_10'] : '';$wr_11 = isset($input_posts['wr_11']) ? $input_posts['wr_11'] : '';echo $wr_10.$wr_11;?>
이렇게 불러왔지만,
Fatal error: Cannot redeclare write_custom_meta_hook() (previously declared in /host/home2/jesiyo/html/skin/functions.php:78) in /host/home2/xxx/html/skin/gnucommerce/skin/board/jungbee/hook.skin.php on line 33
이런 에러가 나네요.
도움 부탁드립니다.
혹시 댓글에도 여분필드로 값을 받을 수 있을까요?
답변 1개 / 댓글 4개
write_custom_meta_hook 을
아래와 같이 function_exists 로 감싸주세요.
if( ! function_exists('write_custom_meta_hook') ){
function write_custom_meta_hook(){
}
}
댓글에는 여분필드를 적용할수 없습니다.
답변에 대한 댓글 4개
그누커머스 사용자가 좀 더 증가하게 되면, 다시 고려해 보겠습니다.
그런데 위 질문내용이 잘 안되네요.ㅜ
hook.skin.php 에
[code]
<?php
//hook과 filter 만 입력하세요.
//https://codex.wordpress.org/Function_Reference/add_action
//https://codex.wordpress.org/Function_Reference/add_filter
add_action('write_update_metadata', 'write_custom_meta_hook', 10, 2); //글을 쓰거나 글을 수정할때 쓰는 hook
if( ! function_exists('write_custom_meta_hook') ){
function write_custom_meta_hook($wr_id, $w){
if( $w == '' ){ //글 입력
} else if ($w == 'u') { //글 수정
}
}
//메타데이터
$etc_array = array();
$input_posts = array(
'wr_10', //여분필드1
'wr_11', //여분필드2
'wr_12', //여분필드3
'wr_13', //여분필드4
'wr_14', //여분필드5
'wr_15', //여분필드6
'wr_16', //여분필드7
'wr_17', //여분필드8
);
foreach( $input_posts as $p ){
$etc_array[$p] = isset($_POST[$p]) ? sanitize_text_field($_POST[$p]) : '';
}
update_metadata( GCBOARD_META_TYPE, $wr_id, 'etc_inputs', $etc_array ); //메타데이터를 업데이트
}
?>
[/code]
이렇게 넣었구요
list.skin.php 에는
<?php echo $v['subject'] ?> 를 질문과 동일한 소스로 바꿨는데
이제 에러는 안나는데 제목에 wr_10 과 wr_11이 아닌 wr_subject 그대로 나오네요.
어떻게 해야 할까요?
아래와 같이 해야 되요.
[code]
if( ! function_exists('write_custom_meta_hook') ){
function write_custom_meta_hook($wr_id, $w){
if( $w == '' ){ //글 입력
} else if ($w == 'u') { //글 수정
}
//메타데이터
$etc_array = array();
$input_posts = array(
'wr_10', //여분필드1
'wr_11', //여분필드2
'wr_12', //여분필드3
'wr_13', //여분필드4
'wr_14', //여분필드5
'wr_15', //여분필드6
'wr_16', //여분필드7
'wr_17', //여분필드8
);
foreach( $input_posts as $p ){
$etc_array[$p] = isset($_POST[$p]) ? sanitize_text_field($_POST[$p]) : '';
}
update_metadata( GCBOARD_META_TYPE, $wr_id, 'etc_inputs', $etc_array ); //메타데이터를 업데이트
}
}
[/code]
답변을 작성하려면 로그인이 필요합니다.