Created
October 17, 2012 11:09
-
-
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.
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
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