在数组中查找 WordPress 模板条件的值
我在 Wordpress 中使用 MagicFields 和重复的成分自定义组。使用单选按钮选择成分类型字段。
我正在尝试编写一个条件语句来仅显示某些成分类型(基料、酱汁等),以便它们可以显示在页面上的不同列表中。
我想要实现的一个例子是:
if (in_array('Base', $IngGroup)) {
echo "Base Ingredients";
}
elseif (in_array('Sauce', $IngGroup)) {
echo "Sauce Ingredients";
}
这是 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] => Array
(
[1] => g
)
[ingredient_amount] => Array
(
[1] => 220
)
[ingredient_name] => Array
(
[1] => Sauce
)
)
)
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] => Array
(
[1] => g
)
[ingredient_amount] => Array
(
[1] => 220
)
[ingredient_name] => Array
(
[1] => Sauce
)
)
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)