Support » Plugin: Strong Testimonials » add another taxonomy and use it in views

  • Resolved aldelpech

    (@aldelpech)


    Hi,

    I need to view testimonials with selected categories and another taxonomy.
    I created a new taxonomy (‘orientation’) for strong testimonials which is registered in a function called by add_action( 'init', 'clea_ib_add_taxonomy_to_strong_testimonial', 11 );.
    When I modify or create testimonials, I can now select or create a “orientation”.

    Is there a solution to display this taxonomy in the views pages so that I may construct views for specific “orientation” ?

    Thanks
    Anne-Laure

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Chris Dillon

    (@cdillon27)

    Hi,

    There is no mechanism for adding custom taxonomies to the view editor. However, there is a filter on the query arguments. Try this function:

    function strong_testimonials_query_args( $args ) {
    	/* using the term ID: */
    	$args['tax_query'] = array(
    		array(
    			'taxonomy' => 'orientation',
    			'field'    => 'id',
    			'terms'    => 123
    		)
    	);
    
    	/* using the term slug: */
    	//$args['tax_query'] = array(
    	//	array(
    	//		'taxonomy' => 'orientation',
    	//		'field'    => 'slug',
    	//		'terms'    => 'whatever'
    	//	)
    	//);
    
    	return $args;
    }
    add_filter( 'wpmtst_query_args', 'strong_testimonials_query_args' );

    Reference: https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    Thread Starter aldelpech

    (@aldelpech)

    Thanks a lot!
    A added this function in my code so that page with id 914 will show only the testimonials with a ‘orientation’ taxonomy set to ‘orientation-isa’ while all other pages will show testiminials with the default ‘orientation’, which is set to ‘orientation-complet’

    function clea_ib_strong_testimonials_query_args( $args ) {
    
    	if ( is_page( 914 ) ) {
    		
    		$orientation_tag_slug = 'orientation-isabelle' ;
    
    	} else {
    		
    		$orientation_tag_slug = 'orientation-complet' ; // is default 'orientation' value
    		
    	}
    
    	/* using the term slug: */
    	$args['tax_query'] = array(
    		array(
    			'taxonomy' => 'orientation',
    			'field'    => 'slug',
    			'terms'    => $orientation_tag_slug
    		)
    	);	
    	return $args;
    }
    add_filter( 'wpmtst_query_args', 'clea_ib_strong_testimonials_query_args' );
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add another taxonomy and use it in views’ is closed to new replies.