Last active
August 29, 2015 14:03
-
-
Save ideag/6e8bee2ca4a086cbc001 to your computer and use it in GitHub Desktop.
Proof of concept - offset get_posts/WP_Query by ID
This file contains hidden or 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 | |
class Klausk_Filter { | |
private $id = 0; | |
private $compare = '<'; | |
public function __construct($id,$compare = '<') { | |
$this->id = intval($id); | |
$this->compare = $compare; | |
} | |
public function filter($where){ | |
$where .= " AND `ID` {$this->compare} {$this->id}"; | |
echo $where; | |
return $where; | |
} | |
} | |
?> |
This file contains hidden or 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 | |
$filter = new Klausk_Filter(500,'<'); | |
$args = array('suppress_filters'=>false); | |
add_filter('posts_where',array($filter,'filter')); | |
$posts = get_posts($args); | |
remove_filter('posts_where',array($filter,'filter')); | |
// do something with $posts | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment