2011-09-30 3 views
0

Wordpress에서 MagicFields를 사용하여 복제 된 성분에 대한 사용자 정의 그룹을 사용 중입니다. 재료 유형 필드는 라디오 버튼으로 선택됩니다.Wordpress 템플릿 조건에 대한 배열에서 값을 찾으십시오.

특정 재료 유형 (기본, 소스 등) 만 표시하는 조건문을 작성하여 페이지의 다른 목록에 표시 할 수 있습니다.

내가 달성하기 위해 노력하고있어의 예는 다음과 같습니다 여기

if (in_array('Base', $IngGroup)) { 
    echo "Base Ingredients"; 
} 
elseif (in_array('Sauce', $IngGroup)) { 
    echo "Sauce Ingredients"; 
} 

은 홍보 ($ IngGroup)의 배열 출력;

Array 
(
[1] => Array 
    (
     [ingredient_type] => Array 
      (
       [1] => Main 
      ) 
     [ingredient_unit] => Array 
      (
       [1] => g 
      ) 
     [ingredient_amount] => Array 
      (
       [1] => 300 
      ) 
     [ingredient_name] => Array 
      (
       [1] => Chicken 
      ) 
    ) 
[2] => Array 
    (
     [ingredient_type] => Array 
      (
       [1] => Sauce 
      ) 
     [ingredient_unit] => Array 
      (
       [1] => g 
      ) 
     [ingredient_amount] => Array 
      (
       [1] => 220 
      ) 
     [ingredient_name] => Array 
      (
       [1] => Sauce 
      ) 
    ) 
) 

답변

1
foreach($IngGroup as $Ing) { 
    if($Ing[ingredient_type][1] == 'Sauce') { 
     echo "Sauce Ingredients"; 
    } elseif ($Ing[ingredient_type][1] == 'Base') { 
     echo "Base Ingredients"; 
    } 
} 
관련 문제