【问题标题】:PHP in array equal/not equal数组中的PHP等于/不等于
【发布时间】:2023-03-05 18:33:01
【问题描述】:

我在 wordpress 网站上工作,但我遇到了数组问题。

代码如下:

'text' => array(
    'type' => 'text',
    'title' => __('Subtitle', 'wpml'),
    'description' => __('Enter subtitle text or leave empty to hide.', 'wpml'),
    'condition' => array('type', '==', 'something1')
),

如何将多个项目放入condition

我需要 3 个项目(something1、something5、something8)与条件相同。

编辑: 这是后端插件的一部分,我可以选择允许输入描述和不允许输入的元素。

这是完整的课程:

function shortcode_options_fields() {

        $this->shortcode_options = array(
                'type' => array(
                'type' => 'select',
                'title' => __('Type', 'wpml'),
                'description' => __('Select services type.', 'wpml'),
                'options' => array(
                    'service1' => __('Service 1', 'wpml'),
                    'service2' => __('Service 2', 'wpml'),
                    'service3' => __('Service 3', 'wpml'),
                    'service4' => __('Service 4', 'wpml'),
                    'service5' => __('Service 5', 'wpml'),
                    'service6' => __('Service 6', 'wpml'),
                    'service7' => __('Service 7', 'wpml'),
                    'service8' => __('Service 8', 'wpml'),
                    'service9' => __('Service 9', 'wpml'),

                ),
                'default' => 'service1'
            ),
            'text' => array(
                'type' => 'text',
                'title' => __('Title', 'wpml'),
                'description' => __('Service title.', 'wpml')
            ),
            'subtitle' => array(
                'type' => 'text',
                'title' => __('Subtitle', 'wpml'),
                'description' => __('Enter subtitle text or leave empty to hide.', 'wpml'),
                'condition' => array()
            ),
            'description' => array(
                'type' => 'textarea',
                'title' => __('Description', 'wpml'),
                'description' => __('Service description.', 'wpml'),
                'condition' => array('type', '==', 'service1')
            ),

        );
    }

只有服务 1,5 和 8 应该没有其他描述。

我希望这会更清楚, 谢谢

【问题讨论】:

  • 这是插件还是 wordpress 核心的一部分?
  • 更多信息,代码 - 在哪里传递给我们或告诉我们
  • 这个“something1”元键是什么?或任何自定义字段?你在 wp-query 中应用这个吗?

标签: php arrays wordpress conditional-statements


【解决方案1】:

您可以在 Wordpres 的文档中找到更多详细信息: https://codex.wordpress.org/

但我相信您正在寻找类似的东西:

'text' => array(
'type' => 'text',
'title' => __('Subtitle', 'wpml'),
'description' => __('Enter subtitle text or leave empty to hide.', 'wpml'),
'condition' => array('type', '==', ('something1', 'something2', 'something3'))
),

【讨论】:

  • 你忘记了:array( ... ) 还是我不明白的东西。
猜你喜欢
  • 1970-01-01
  • 2011-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-10
  • 2014-04-27
  • 1970-01-01
  • 2020-05-29
相关资源
最近更新 更多