-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloopy.php
More file actions
32 lines (30 loc) · 809 Bytes
/
loopy.php
File metadata and controls
32 lines (30 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
/* Plugin Name: loopy
* Plugin URI: https://github.com/drdf/loopy
* Description: For the loopy developers who want to iterate with `foreach` over `WP_Query`.
* Version: 1.0.0
* Author: David Ringsdorf
* Author URI: https://davidringsdorf.de/
* License: MIT
* Text Domain: loopy
*/
if (!function_exists('loopy')) {
/**
* loopy
*
* For the loopy developers who want to iterate with `foreach` over `WP_Query`.
*
* @author David Ringsdorf <https://davidringsdorf.de/>
* @package loopy
* @version 1.0.0
* @license MIT
*/
function loopy(WP_Query $wpQuery) {
$wpQuery->rewind_posts();
while ( $wpQuery->have_posts() ) {
$wpQuery->the_post();
yield get_post();
}
wp_reset_postdata();
}
}