# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Page Builders & Themes](https://wpide.com/library/category/page-builders/)
- Tags: elementor, query, popular, comments
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/elementor-query-most-commented/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Elementor Posts Query: Most Discussed Posts" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
