Skip to content

Instantly share code, notes, and snippets.

@nacin
Created May 14, 2013 03:08
Show Gist options
  • Save nacin/5573377 to your computer and use it in GitHub Desktop.
Save nacin/5573377 to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: Hacky Taxonomy Archives
* Description: Don't use this on a live site, plz. Proof of concept for Aaron Holbrook.
* Author: Andrew Nacin
*/
add_action( 'template_redirect', function() {
global $wp_rewrite;
$taxonomy = 'fruits';
add_rewrite_rule( 'fruits/?$', 'index.php?taxonomy=fruits', 'top' );
add_rewrite_rule( 'fruits/' . $wp_rewrite->pagination_base . '/([0-9]{1,})/?$', 'index.php?taxonomy=fruits&paged=$matches[1]', 'top' );
} );
add_action( 'pre_get_posts', function( $query ) {
if ( ! $query->is_main_query() )
return;
if ( $query->get( 'taxonomy' ) == 'fruits' && ! $query->get( 'term' ) ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => 'post_tag',
'terms' => get_terms( 'post_tag', array( 'fields' => 'ids' ) ),
'field' => 'term_id',
)
) );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment