Skip to content

Instantly share code, notes, and snippets.

@chrisjdavis
Created November 16, 2012 01:25
Show Gist options
  • Save chrisjdavis/4083076 to your computer and use it in GitHub Desktop.
Save chrisjdavis/4083076 to your computer and use it in GitHub Desktop.
<?php
function is_subcat( $term ) {
global $wpdb;
$check = $wpdb->get_var( "SELECT terms_id FROM " . $wpdb->prefix . "termsmeta WHERE meta_value = '" . $term . "' AND meta_key = 'non-unique-slug'" );
if( $check == NULL ) {
return false;
} else {
return true;
}
}
function enable_non_unique_subcats( $query ) {
global $wpdb, $parent, $child;
if( is_subcat($query->query_vars['attachment']) == true ) {
$bits = explode('/', $_SERVER['REQUEST_URI'] );
$c = array_pop( $bits );
$p = array_pop( $bits );
$parent = get_category_by_slug( $p );
$ch = $wpdb->get_results( "SELECT terms_id FROM " . $wpdb->prefix . "termsmeta WHERE meta_value = '" . $parent->slug . "' AND meta_key = 'parent'" );
foreach( $ch as $chld ) {
$candidates = $wpdb->get_results( "SELECT terms_id, meta_value FROM " . $wpdb->prefix . "termsmeta WHERE terms_id = " . $chld->terms_id . " AND meta_key = 'non-unique-slug'" );
foreach( $candidates as $candies ) {
if( $candies->meta_value == $c ) {
$child = get_category($candies->terms_id);
}
}
}
load_template( TEMPLATEPATH . '/subcat.php' );
}
}
add_action( 'pre_get_posts', 'enable_non_unique_subcats' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment