Sort Posts by Cat Name
-
I am creating a Dropdown selection box with a list of custom post types with them prefixed by their category name. Each post will only have one category name. This is what I have at the moment. How would I sort them by the Category Name?
echo '<option value="-1">--Select a Product--</option>'; while ( $query->have_posts() ) : $query->the_post(); $id = get_the_ID(); echo '<option value="' .$id. '"' .selected( $product, $id ). '>'; $category = get_the_terms( $id->ID, 'product_cat' ); foreach ( $category as $cat){ echo $cat->name . ' - '; } the_title(); echo '</option>'; endwhile;[Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]
Any insights into a solution are greatly appreciated.
– Michael
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Sort Posts by Cat Name’ is closed to new replies.