Last active
December 20, 2015 13:39
-
-
Save tomjn/6140601 to your computer and use it in GitHub Desktop.
If you're lucky enough to be using any version of PHP 5 with WordPress ( 100% chance! ) You can do this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$posts = new posts_loop(); | |
foreach( $posts as $id => $post ) { | |
the_title(); | |
// etc... | |
} | |
// put this below in your functions.php: | |
/** | |
* WordPress Main Posts Loop Iterator | |
*/ | |
class posts_loop implements Iterator { | |
public function __construct() { } | |
function rewind() { | |
rewind_posts(); | |
} | |
function current() { | |
global $post; | |
return $post; | |
} | |
function key() { | |
global $post; | |
return $post->ID; | |
} | |
function next() { | |
the_post(); | |
} | |
function valid() { | |
return have_posts(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment