Skip to content

Instantly share code, notes, and snippets.

@cdillon
Last active March 2, 2017 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdillon/3fe1a907cdc9a7d7e010 to your computer and use it in GitHub Desktop.
Save cdillon/3fe1a907cdc9a7d7e010 to your computer and use it in GitHub Desktop.
/**
* A shortcode to display the number of testimonials.
*
* For Strong Testimonials plugin.
*
* For all: [my_testimonial_count]
* For a specific category (by slug): [my_testimonial_count category="abc"]
*
* @param $atts
* @param null $content
*
* @return int
*/
function my_testimonial_count( $atts, $content = null ) {
$atts = shortcode_atts(
array(
'category' => '',
),
$atts
);
$args = array(
'posts_per_page' => -1,
'post_type' => 'wpm-testimonial',
'post_status' => 'publish',
'wpm-testimonial-category' => $atts['category'],
'suppress_filters' => true,
);
$posts_array = get_posts( $args );
return count( $posts_array );
}
add_shortcode( 'my_testimonial_count', 'my_testimonial_count' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment