Forums

Custom taxonomy - sorting by something other than alphabetically (2 posts)

  1. tmrickett
    Member
    Posted 1 year ago #

    Hi

    I'm building a real estate website and I'm using custom taxonomy for property features. The features fall into three 'categories' which are displayed in three columns on the property details page. Each colum/'category' has the relevant features for that property. Below is how I am getting it to display on the single_listing page.

    $arr_terms = get_the_terms($post->ID, 'property_features');
    if ($arr_terms) {
    
    		echo "<div id='featurecategories'>";
    		if ($arr_terms) {
    
    		foreach ($arr_terms as $item) {
    			if($item->parent == 0) {
    			$cat_id = $item->term_id;
    			echo "<div class='featuresblock'>";
    			echo "<h4>". $item->name . "</h4>";
    
    			echo "<ul>";
    			foreach ($arr_terms as $item2) {
    
    				if($item2->parent == $cat_id) {
    				 echo "<li><a href='". get_term_link($item2, 'property_features') ."'>". $item2->name . "</a></li>";
    				}
    
    			}
    			echo "</ul>";
    			echo "</div>";
    			}
    		}
    		}
    		echo "</div>";
    
    }

    The problem is that this displays everything alphabetically, and I want to sort it in my own order. One way I thought would be to number the slugs, and then sort it by them. Does anyone know how I would amend the above code so that it displays the same content but sorted by slug?

    Or if there is another way to achieve the same, I'd be happy to use that.

    Thanks in advance!

  2. Zack Tollman
    Member
    Posted 10 months ago #

    You can give my new plugin a try: http://wordpress.org/extend/plugins/custom-taxonomy-sort/. It's aimed at automatically sorting taxonomies, including custom taxonomies, by a user specified order.

    EDIT: Actually, my plugin will not work with this just yet. I need to make a slight change so it will work in this context. I should have an update up in a day or so.

Topic Closed

This topic has been closed to new replies.

About this Topic