• Hi,

    Thank you for sharing your work.

    I have this project were I’m thinking of using Good Reviews but I’m not sure I can get it to do what I need.

    I have a courses CPT, with a topics custom taxonomy. Is there a way for me to show reviews for specific course topics, instead of the review category taxonomy?

    Thanks.

    álvaro

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Alvaro,

    To accomplish this, you’ll need to associate the taxonomy with the reviews post type. Pippin wrote a great little tutorial on doing this here:

    https://pippinsplugins.com/add-already-registered-taxonomy/

    You’d want the second snippet which fires after all plugins are loaded.

    That still won’t get you a convenient shortcode, though. To get there, you’d need to add an optional query arg for your topics term:

    
    add_filter( 'grfwp_query_args', function( $args ) { 
    
      if ( !empty( $args['topic'] ) ) {
        $this->args['tax_query'] = array(
          array(
            'taxonomy' => 'topic',
            'field' => 'slug',
            'terms' => $args['topic'],
          )
        );
      }
    
      return $args;
    } );
    

    Then register your own custom shortcode which accepts this new topic parameter (this code just copies with slight modifications what’s in includes/template-functions.php:

    
    function alvaro_grfwp_reviews_shortcode( $atts ) {
    
    	// We must disable the automatic append to content filter while we're
    	// rendering the shortcode to prevent it from displaying twice
    	global $grfwp_controller;
    	remove_action( 'the_content', array( $grfwp_controller, 'append_to_content' ) );
    
    	$output = grfwp_print_reviews(
    		shortcode_atts(
    			array(
    				'review' 	=> null,
    				'category' 	=> null,
    				'random'	=> false,
    				'limit'		=> null,
    				'cycle'		=> false,
    				'excerpt'	=> false,
    				'topic'		=> false,
    			),
    			$atts
    		)
    	);
    
    	// Restore the_content filter
    	add_action( 'the_content', array( $grfwp_controller, 'append_to_content' ) );
    
    	return $output;
    }
    add_shortcode( 'alvaro-good-reviews', 'alvaro_grfwp_reviews_shortcode' );
    

    That should do the trick, but please bear in mind that none of this code has been tested. You may need to work through typos or other issues.

    Thread Starter Alvaro Gois dos Santos

    (@alvarogois)

    Wow, this is really awesome @natewr!

    I’ll dig into the code and let you know how it goes.

    Thanks.

    álvaro

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show review by custom taxonomy?’ is closed to new replies.