Created
July 17, 2012 22:42
-
-
Save kopepasah/3132619 to your computer and use it in GitHub Desktop.
Order Custom Post Type Archive by Taxonomy in WordPress
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 | |
/** | |
* 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' => 'DESC' ) ); | |
foreach ( $taxonomies as $taxonomy ) { | |
echo '<div id="' . $taxonomy->slug . '">'; | |
echo '<h1 class="title" >' . $taxonomy->name . '</h1>'; | |
$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
hello how are you, as I can sort the results by using the url taxonomies, such orderby=sex&order= ASC. Thank you very much