调用PHP Wordpress简码-警告:in_array()期望参数2为数组,字符串在

时间:2018-07-24 13:53:31

标签: php wordpress shortcode

我正在使用wordpress和2个名为unyson和brizy的插件。 基本上,unyson为我提供了一个短代码,我想通过其首页上的首页生成器轻松进行调用。

我想用[投资组合]来调用投资组合的简码。 这行得通。

实时网站:https://xprs.ch/ 在“我们的工作档案”下

现在我要添加选项: [portfolio page_link =“在”类别=“网站”]

只要我只定义page_link即可。 但是,一旦我尝试定义类别,就会出现以下错误:

Warning: in_array() expects parameter 2 to be array, string given in /home/httpd/vhosts/xprs.ch/httpdocs/wp-content/themes/jevelin/framework-customizations/extensions/shortcodes/shortcodes/portfolio/views/view.php on line 100

如果仅定义类别,我也会遇到上述错误,因此我需要定义不同的内容,但是如何?

简码中的代码: 注意:我不能更改此代码。 我需要在前端正确传递参数“网站”。

$options = array(

    'id' => array( 'type' => 'unique' ),
    'general' => array(
        'title'   => esc_html__( 'General', 'jevelin' ),
        'type'    => 'tab',
        'options' => array(

            'style' => array(
                'type'    => 'radio',
                'label'   => esc_html__('Style', 'jevelin'),
                'desc'  => esc_html__('Choose main style', 'jevelin'),
                'choices' => array(
                    'default' => esc_html__('Standard', 'jevelin'),
                    'default-shadow' => esc_html__('Standard with Shadow', 'jevelin'),
                    'default2' => esc_html__('Trendy', 'jevelin'),
                    'masonry' => esc_html__('Gallery', 'jevelin'),
                    'masonry2' => esc_html__('Marginless Gallery', 'jevelin'),
                    'minimalistic' => esc_html__('Minimalistic', 'jevelin'),
                ),
                'value'   => 'default',
            ),

            'categories' => array(
                'type'  => 'multi-select',
                'label' => esc_html__('Categories', 'jevelin'),
                'desc'  => esc_html__('Select categories', 'jevelin'),
                'population' => 'taxonomy',
                'source' => 'fw-portfolio-category',
                'prepopulate' => 200,
                'limit' => 100,
            ),

            'page_link' => array(
                'type' => 'switch',
                'label' => esc_html__( 'Page Link', 'jevelin' ),
                'desc' => esc_html__( 'Enable or disable portfolio page link', 'jevelin' ),
                'value' => true,
                'left-choice' => array(
                    'value' => false,
                    'label' => esc_html__('Off', 'jevelin'),
                ),
                'right-choice' => array(
                    'value' => true,
                    'label' => esc_html__('On', 'jevelin'),
                ),
            ),

        ),
    ),
);

我该如何称呼类别?

1 个答案:

答案 0 :(得分:-2)

这里:

$cats = array();
foreach( get_the_category() as $cat ) {
    $cats[] = $cat->cat_ID;
}
$args = array(
    'post_status'    => 'publish',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy'         => 'category',
            'field'            => 'id',
            'terms'            => $cats,
            'include_children' => false
        )
    )
);
print_r( WP_Query( $args ) as $post );

http://codex.wordpress.org/Class_Reference/WP_Query