Skip to content

Instantly share code, notes, and snippets.

@joehoyle

joehoyle/advanced.php

Last active Oct 12, 2015
Embed
What would you like to do?
<?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
You can’t perform that action at this time.