Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 96074

the.green.timtam on "Displaying Custom Taxonomy Archive in Ascending Order"

$
0
0

Hello,

I'm having issues displaying my taxonomy archive loops in ascending order.

I have a taxonomy called 'enemies' which applies to four custom post types. I want to display all of them in a loop in ascending order.

So far I've got this in my taxonomy-enemies.php file:

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
        <?php endwhile; ?>
      <?php endif; ?>

which displays 10 in descending order. I tried adding query_posts:

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>
<?php query_posts(array('posts_per_page' => -1, 'orderby'=> date, 'order'=>ASC));
if (have_posts()) : while (have_posts()) : the_post(); ?>

But that makes the loop only display posts (not custom post types), even though they are not given the enemies taxonomy. I tried this:

<?php query_posts(array('posts_per_page' => -1, 'post_type' => array('post-type-1', 'post-type-2', 'post-type-3', 'post-type-4'), 'orderby'=> date, 'order'=>ASC, 'taxonomy'=>'enemies', 'term'=>'enemy-slug'));
if (have_posts()) : while (have_posts()) : the_post(); ?>

This works perfectly when I replace 'enemy-slug' with the slug of an enemy, but I can't work out how to make it generate from the archive that is currently being displayed.


Viewing all articles
Browse latest Browse all 96074

Trending Articles