Elementor Posts Query: Most Discussed Posts
Adds a custom query ID "wpide_popular" that orders posts by number of comments, to build a "Most discussed" block with Elementor Pro.
Opens WPIDE on
Code
add_action( 'elementor/query/wpide_popular', function ( $query ) {
$query->set( 'orderby', array( 'comment_count' => 'DESC', 'date' => 'DESC' ) );
$query->set( 'ignore_sticky_posts', true );
} );
Notes
Type wpide_popular in the Query ID field. Set the number of posts in the widget as usual.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.