Created
November 16, 2012 01:25
-
-
Save chrisjdavis/4083076 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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