开发者

Find value in array for Wordpress template condition

I am using MagicFields in Wordpress with a custom group for Ingredients which is duplicated. The ingredient type field is selected with a radio button.

I am trying to write a conditional statement to only show certain ingredient types (Base, Sauce, etc) so they can be shown in different lists on the page.

An example of what I'm trying to achieve is:

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

Here is the array output from pr($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] =&g开发者_运维百科t; Array
            (
                [1] => g
            )
        [ingredient_amount] => Array
            (
                [1] => 220
            )
        [ingredient_name] => Array
            (
                [1] => Sauce
            )
    )
)


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜