2015-01-21 1 views
0

PHP 목록() 형식으로 값을 반환하는 PHP 함수가 있습니다. 이 함수는 두 개의 사용자 정의 항목이 수동으로 추가 된 WordPress 분류 목록을 반환합니다.저장된 배열 값을 사용하고 액세스하는 방법

/** 
* Returns array with taxonomies 
*/ 
public function get_taxonomies(){ 
    $args = array(
     'public' => true, 
     '_builtin' => false 
    ); 
    $taxonomies = get_taxonomies($args, 'objects'); 
    $list = array(); 
    $list[__('Category', $this->prefix)] = 'category'; 
    $list[__('Tag', $this->prefix)] = 'post_tag'; 
    foreach($taxonomies as $tax){ 

     $list[$tax->labels->name] = $tax->name; 
    } 
    return $list; 
} 

이 함수는 다음과 같은 배열의 값을 리턴 배열

Array 
(
    [Category] => category 
    [Tag] => post_tag 
    [Product Categories] => product_cat 
    [Product Tags] => product_tag 
    [Shipping Classes] => product_shipping_class 
) 

첫 번째 부분은 분류 이름 및 분류 값 제.

이 값을 확인란 목록으로 표시하고이를 데이터베이스로 배열로 저장합니다.

이것은 데이터베이스의 체크 박스 목록에 저장하는 데이터입니다.

Array 
(
    [category] => category 
    [post_tag] => post_tag 
    [product_cat] => product_cat 
) 

난으로 표시 데이터베이스에 저장된 값으로 분류 체계의 초기 목록을 반환하려고 체크 워드 프레스() 함수를 사용 : 나는이 목록에 대한 데이터를 저장) (print_r의 경우에 반환되는 것입니다 HTML "checked". 여기

내가 시도 것입니다 :
// This is where I am trying to get at the saved values 
$multi_stored = $options[$id]; 

$taxonomies = $this->get_taxonomies(); 
foreach($taxonomies as $name => $label){ 

    $check_key = $id . '_' . $option; 

    $output .= '<input class="checkbox'.$field_class.'" type="checkbox" name="'.$this->prefix.'_options['.$id.']['.$label.']" id="'.$check_key.'" value="'.$label.'" '.checked($multi_stored[$label], $label, false).' /><label for="'.esc_attr($name).'">'.esc_html($name).'</label><br />'; 
} 

나는 다음과 같은 PHP 경고를받은이 코드를 실행

.

공지 사항 : 정의되지 않은 인덱스 : C에서 여기서 product_tag : \ XAMPP \ htdocs를 \ wpbp-admin.php 라인 ...

그것은 체크 박스에있는 모든 항목에 대해 나에게이 경고를주고있다 체크되지 않은 목록.

나는 이러한 경고를 반환하지 않는 코드를 갖고 싶습니다. 나는 그것이 isset을 사용하는 문제이지만 그것이 어디에 위치해야할지 모르겠다는 것을 이해합니다.

도움을 주시면 감사하겠습니다.

답변

0

나는 그것을 작동시켰다.

나는이에 루프 기능을 "검사"로 변경 :

$multi_stored = $options[$id]; 

$taxonomies = $this->get_taxonomies(); 
foreach($taxonomies as $name => $label){ 

    if(isset($multi_stored[$label])){ 
     if($label == $multi_stored[$label]){ 
      $checked = 'checked="checked"'; 
     } else { 
      $checked = ''; 
     } 
    } else { 
     $checked = ''; 
    } 

    $check_key = $id . '_' . $label; 

    $output .= '<input class="checkbox'.$field_class.'" type="checkbox" name="'.$this->prefix.'_options['.$id.']['.$label.']" id="'.$check_key.'" value="'.$label.'" '.$checked.' /><label for="'.esc_attr($name).'">'.esc_html($name).'</label><br />'; 
} 
관련 문제