Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

It seems like something really simple, however I can't find a good solution to what I am looking for. I created a page template that shows all my taxonomy term of a taxonomy called "news" eg: paper1, paper2 etc etc

this is the code I generated:

<?php
$post_type = 'article';
$tax = 'news';
$tax_terms = get_terms( $tax );
if ($tax_terms) {
    foreach ($tax_terms  as $tax_term) {
    $args = array(
        'post_type' => $post_type,
        "$tax" => $tax_term->slug,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'order' => 'ASC',
        'caller_get_posts'=> 1
    );

        $my_query = null;
        $my_query = new WP_Query($args);

        if( $my_query->have_posts() ) : ?>

//here comes my styling for any term including it's custom post types

<?php else : ?>
        <?php endif; // if have_posts()
        wp_reset_query();

    } // end foreach #tax_terms
}
?>

everything works fine and the page generate all the taxonomy terms and their posts one by one like so (just a demonstration of course..):

paper1
 - article 1
 - article 1
 - article 1
 - article 1

paper2
 - article 1
 - article 1
 - article 1
 - article 1

paper3
 - article 1
 - article 1
 - article 1
 - article 1

The problem is that it displays everything in an a Descending order and I want to change it to Ascending. I always need to latest "paper" to show on top. Notice that I did add:

'order' => 'ASC',

to my arguments but it doesn't work on custom taxonomy terms and it keeps showing all the terms (papers) in a Descending order. I thought it should work like regular categories but surprisingly it doesn't.

can anyone help?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You're not setting an order anywhere for get_terms, you're setting it for the query of articles within each term. You need to pass arguments to get_terms if you want an order other than default, which is ASC.

$tax = 'news';
$tax_args = array(
    'order' => 'DESC'
);
$tax_terms = get_terms( $tax, $tax_args );
share|improve this answer
    
Working like a charm! Thanks Milo!! –  gil hamer Mar 14 '13 at 23:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.