Skip to content

Instantly share code, notes, and snippets.

@joehoyle
Last active October 12, 2015 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehoyle/4040324 to your computer and use it in GitHub Desktop.
Save joehoyle/4040324 to your computer and use it in GitHub Desktop.
<?php
hm_rewrite_rule( array(
'regex' => '^reviews/([^/]+)/?', // a review category page
'query' => 'review_category=$matches[1]&',
'template' => 'review-category.php',
'request_callback' => function( WP $wp ) {
// if the review category is "laptops" then only show items in draft
if ( $wp->query_vars['review_category'] == 'laptops' )
$wp->query_vars['post_status'] = 'draft';
},
'query_callback' => function( WP_Query $query ) {
//overwrite is_home because WordPress gets it wrong here
$query->is_home = false;
},
'body_class_callback' => function( $classes ) {
$classes[] = get_query_var( 'review_category' );
return $classes;
},
'title_callback' => function( $title, $seperator ) {
return review_category . ' ' . $seperator . ' ' . $title;
}
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment