Skip to content

Instantly share code, notes, and snippets.

@kopepasah
Created July 17, 2012 22:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kopepasah/3132619 to your computer and use it in GitHub Desktop.
Save kopepasah/3132619 to your computer and use it in GitHub Desktop.
Order Custom Post Type Archive by Taxonomy in WordPress
<?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();
@eduardogarrido
Copy link

hello how are you, as I can sort the results by using the url taxonomies, such orderby=sex&order= ASC. Thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment