Fetch existing numbers of maximum number of commented post/products

please click here for more wordpress cource

If you want to fetch maximum number of commented post. then it is easy for you. you can fetched with out plugin only use the short code.

  • Include file in function.php.
  • Save file theme directory.
  • Past short code in any post or page.
// function that runs when shortcode is called
function wpb_demo_shortcode() { 
// Things that you want to do. 
 $most_commented = new WP_Query( array( 'post_type' => array( 'post','product' ), 'posts_per_page' => 2, 'order' => 'DESC', 'orderby' => 'comment_count', 'ignore_sticky_posts' => true ) );
	if( $most_commented->have_posts() ) : ?>
		<section class="most-commented-posts">
			<h5 class="section-title">Most Commented Posts</h5>
<?php while( $most_commented->have_posts() ) :
		$most_commented->the_post(); ?>
			<div class="section-entry">
				<h6 class="most-commented-post-title"><?php the_title(); ?></h6>
				Comment count: <?php echo get_comments_number(); ?>
<?php endwhile; ?>
<?php endif;
// Output needs to be return
//return $message;
// register shortcode
add_shortcode('shortcode_custom', 'wpb_demo_shortcode'); 

This is us-full for the maximum number of commented post fetch by using this script you don’t need any plugin and only use above given script for maximum commented post

If you want to watch video of this tutorial please click on given below Youtube link
click here

use this code in any page or post where you want to show the all post and products


If you want to learn WordPress theme development it is best place for you

You may also like...

Popular Posts

Leave a Reply

Your email address will not be published. Required fields are marked *