在Visual Composer(WPBakery)中保存下拉类别列表的值 [英] Save value of dropdown categories lists in Visual Composer (WPBakery)

查看:119
本文介绍了在Visual Composer(WPBakery)中保存下拉类别列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码

  $ categories_array = array(__('All Categories','js_composer')=>'mp-all-categories'); 
$ category_list = get_terms('download_category',array('hide_empty'=> false));

if(is_array($ category_list)&&!empty($ category_list)){
foreach($ category_list as $ category_details){
$ begin = __ (ID:','js_composer');
$ end = __(')','js_composer');
$ categories_array [$ category_details-> name。 $开始。 $ category_details-> term_id。 $ end] = $ category_details-> term_id;
}
}


vc_map(array(
...
params=> array(
array (
'type'=>'dropdown',
'heading'=> __('Select Category','js_composer'),
'param_name'=>'mp_category' ,
'value'=> $ categories_array,
'description'=> __('选择类别','js_composer'),
),

这是我在

  if($ categories_array!='mp-all-categories'){
$ args ['tax_query'] [] = array(
'taxonomy'=>'download_category ',
'field'=>'term_id',
'terms'=> $ categories_array
//'terms'=>'23',

);

$ categories_array 似乎不起作用。



当我从列表中选择一个类别时,没有帖子显示,而我知道有帖子在类别内。任何人都知道我在做错什么?

解决方案

解决这个问题非常简单。我应该使用参数名称。如果($ mp_category!=''){
$ args ['tax_query'] [] =

 array(
'taxonomy'=>'download_category',
'field'=>'term_id',
'terms'=> $ mp_category

);
}


I'm stuck on a problem and don't know how to solve it.

This is my code

$categories_array = array( __( 'All Categories', 'js_composer' ) => 'mp-all-categories' );
$category_list = get_terms( 'download_category', array( 'hide_empty' => false ) );

    if ( is_array( $category_list ) && ! empty( $category_list ) ) {
        foreach ( $category_list as $category_details ) {   
            $begin = __(' (ID: ', 'js_composer');
            $end = __(')', 'js_composer');
            $categories_array[ $category_details->name . $begin. $category_details->term_id . $end ] = $category_details->term_id;  
        }
    }


 vc_map( array(
   ...
   "params" => array(    
    array(
        'type' => 'dropdown',
        'heading' => __( 'Select Category', 'js_composer' ),
        'param_name' => 'mp_category',
        'value' => $categories_array,           
        'description' => __( 'Select a category', 'js_composer' ),
    ),  

And this is the code I'm having problems with

if( $categories_array != 'mp-all-categories' ) {
        $args['tax_query'][] = array(
            'taxonomy'           => 'download_category',
            'field'              => 'term_id',
            'terms'              => $categories_array
            //'terms'            => '23',

        );

The $categories_array doesn't seem to work.

When I select a category from the list, no posts show up while I know there are posts inside the category. Anyone an idea what I'm doing wrong?

解决方案

Solution to this question was extremely easy. I should've used the param name instead. :)

if( $mp_category != '' ) {
            $args['tax_query'][] = array(
                'taxonomy'           => 'download_category',
                'field'              => 'term_id',
                'terms'              => $mp_category

            );
          } 

这篇关于在Visual Composer(WPBakery)中保存下拉类别列表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆