-
-
Save zedejose/5595218 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/* | |
* 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