Skip to content

Instantly share code, notes, and snippets.

@styledev
Created October 17, 2012 11:09
Show Gist options
  • Save styledev/3904986 to your computer and use it in GitHub Desktop.
Save styledev/3904986 to your computer and use it in GitHub Desktop.
This will allow you to use /?range=a,e which will then return all posts with a post title that begins with an A,B,C,D,or E.
public function range_add($aVars) {
$aVars[] = "range";
return $aVars;
}
public function range_where( $where, $args ) {
if( !is_admin() ) {
$range = ( isset($args->query_vars['range']) ? $args->query_vars['range'] : false );
if( $range ) {
$range = split(',',$range);
$where .= "AND LEFT(wp_posts.post_title,1) BETWEEN '$range[0]' AND '$range[1]'";
}
}
return $where;
}
add_filter( 'query_vars', array('atk','range_add') );
add_filter( 'posts_where' , array('atk','range_where') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment