Skip to content

Commit cbc7db9

Browse files
authored
Filter the number of posts in a Posts Widget (#334)
1 parent 31ef8ca commit cbc7db9

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/hooks/custom-query-filter.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ function my_query_by_post_status( $query ) {
131131
add_action( 'elementor/query/{$query_id}', 'my_query_by_post_status' );
132132
```
133133

134+
### Increase the Number of Posts in a Posts Widget
135+
136+
Use the following to change the number of displayed posts in a posts widget:
137+
138+
```php
139+
/**
140+
* Update the query to set how mamy posts to display.
141+
*
142+
* @since 1.0.0
143+
* @param \WP_Query $query The WordPress query instance.
144+
*/
145+
function my_query_posts_per_page( $query ) {
146+
$query->set( 'posts_per_page', 20 );
147+
}
148+
add_action( 'elementor/query/{$query_id}', 'my_query_posts_per_page' );
149+
```
150+
134151
## Notes
135152

136153
You may need to refresh the [editor](./../editor/) to see the filter's effect.

0 commit comments

Comments
 (0)