I am using which code which returns taxonomies which match 2 values.
Everything works as it should, but I can’t figure out how to order my results. Right now they are displayed in some set order, it might be date not sure. I am trying to get them to display alphabetically (by name)..
My Code from my php template is pasted here http://pastie.org/5083124
The array I am talking about is this
<?php
foreach ( $all_terms as $all_term) {
//print_r($all_terms);
$tax_test = get_option('woo_categories_panel_taxonomies_'.$all_term->taxonomy);
$post_images = array();
$posts_aray = array();
$parent_id = $all_term->term_taxonomy_id;
$term_name = $all_term->name;
$term_parent = $all_term->parent;
$term_slug = $all_term->slug;
$term_id = $all_term->term_id;
$term_link = get_term_link( $all_term, $all_term->taxonomy );
$counter_value = $all_term->count;
?>
<div class="childListings">
<div class="block">
<a href="<?php echo $term_link; ?>">
<?php
$block_counter++;
?>
</a>
<h2><a href="<?php echo $term_link; ?>"><?php echo $term_name ?> <br/><span>(<?php echo $counter_value; ?> Solicitors)</span></a></h2>
</div><!-- /.block -->
</div><!-- /.child Listings-->
<?php
if ( $block_counter % 6 == 0 ) {
?>
<div class="fix"></div>
<?php
} // End IF Statement
// End IF Statement
?>
<?php
} // End For Loop
?>
I have looked at a few different options with $args and ksort, but I get a bit lost and can’t seem to get my results on the frontend of the site to be sorted alphabetically.
Can anyone identify in my code how I would be able to have my results have a sort order?
Thanks
You can avoid bothering to sort in the PHP by sorting slightly earlier, when you’re querying the database. This should be faster.
Change:
…to:
i.e. just add
ORDER BY nameto your original query. The results will be returned sorted by name with no need for you to do anything further in the PHP, and the sort will happen on the database server. The WordPress database tabletermshas an index on thenamecolumn, so this should be very fast; effectively the data is pre-sorted for you. (See the description of thetermstable in the WP database schema.)