• I am currently using a Visual Composer enabled theme for my company’s website. This copy of Visual Composer has a custom post type called ‘Testimonial’ which syncs with a Visual Composer element. The VC element allows you to only display testimonials of a certain category. Unfortunately, when creating a post under the testimonials tab, there is no field in which I can select a category. This means no matter what page I use the element on, it only displays testimonials in chronological order and I cannot choose which ones go on each page. Any idea how I can make this category field appear?

    I also attempted to use the plugin called “Advanced Custom Fields” and it allowed me to create a field but these categories are not detectable by VC. Any ideas?

    Here is the link to my WIP site:
    https://www.gkspolishing.com/w15x/

Viewing 1 replies (of 1 total)
  • Hi,

    First of all you need to create child theme and switch to it in order to prevent further theme updates from overwriting your customizations.

    In the child theme’s function.php add the following code:

    add_action( 'init', 'bbchild_init' );
    function bbchild_init() {
    
      if ( function_exists( 'vc_add_param' ) ) {
        $testimonial_categories_array = get_terms( 'testimonial_category' );
        $testimonial_categories = array(
          __( 'All', 'bestbuild' ) => 'all'
        );
        if( $testimonial_categories_array && ! is_wp_error( $testimonial_categories_array )  ){
          foreach( $testimonial_categories_array as $cat ){
            $testimonial_categories[$cat->name] = $cat->slug;
          }
        }
    
        // Adding Category parameter to the VC module
        vc_add_param( 'stm_testimonials', array(
          'type' => 'dropdown',
          'heading' => __('Category', 'bestbuild'),
          'param_name' => 'category',
          'value' => $testimonial_categories
        ) );
      }
    
    }

    Check the backend to ensure our new field appears in testimonials module.

    Then copy template vc_templates/stm_testimonials.php from original theme to the child theme directory and do the following modifications (new lines highlighted with +++):

    extract( shortcode_atts( array(
      'css'      => '',
      'count'    => 1,
      'category' => 'all' // +++
    ), $atts ) );
    
    // ...
    
    if( $category != 'all' ){  // +++
      $args['testimonial_category'] = $category;  // +++
    }  // +++
    $testimonials = new WP_Query( $args );

    Check your module on the frontend. Testimonials should be filtered by selected category.

    Hope it helps, if no, please send your request to https://stylemix-wp-support.com/request-a-quote/

    Regards,
    Azamat
    Stylemix WP Support

Viewing 1 replies (of 1 total)

The topic ‘[Visual Composer] Testimonial Categories’ is closed to new replies.