-
-
Save omurphy27/bd112dd020eedd61aaf4 to your computer and use it in GitHub Desktop.
Order Custom Post Type Archive by Taxonomy in WordPress
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 | |
/** | |
* Template for ordering custom post types by terms on | |
* on the post types archive.php | |
* | |
* @package WordPress | |
* @author Justin Kopepasah | |
* | |
*/ | |
get_header(); | |
global $post; | |
$taxonomies = get_terms( 'taxonomy_name', array( 'order' => 'ASC' ) ); | |
foreach ( $taxonomies as $taxonomy ) { | |
echo '<div class="' . $taxonomy->slug . '">'; | |
echo '<h2>' . $taxonomy->name . '</h2>'; | |
$args = array( | |
'tax_query' => array( | |
array( | |
'taxonomy' => $taxonomy->taxonomy, | |
'field' => 'slug', | |
'terms' => array( $taxonomy->slug ), | |
) | |
) | |
); | |
query_posts( $args ); | |
if ( have_posts() ) : | |
while ( have_posts() ) : the_post(); | |
## post html goes here. | |
endwhile; | |
endif; | |
wp_reset_query(); | |
echo '</div>'; | |
} // end foreach | |
get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment