Skip to content

Instantly share code, notes, and snippets.

@ideag
Last active August 29, 2015 14:03
Show Gist options
  • Save ideag/6e8bee2ca4a086cbc001 to your computer and use it in GitHub Desktop.
Save ideag/6e8bee2ca4a086cbc001 to your computer and use it in GitHub Desktop.
Proof of concept - offset get_posts/WP_Query by ID
<?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;
}
}
?>
<?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