Ordering Posts and Terms in ASC order
-
I have a website where I have a product page, where are all the products with categories and products posts which have no categories.
I need all the categories and products sorted by a name (ASC order), so all of them will be output in correct order and not like categories comes then comes products.
Issue is I dont know how to do that. I could be able to combine both arrays. But how to I output them, if one needs foreach loop and other needs while loop.
I have figured out how to output all posts with no categories and all the categories.
Here’s my code:
<?php // post array $posts = new WP_Query( array( 'post_type' => $post_type, 'tax_query' => array( array( 'taxonomy' => $taxonomy, 'field' => 'term_id', 'operator' => 'NOT IN', 'terms' => get_terms( $taxonomy, array('fields' => 'ids') ) )) )); $args = array( 'parent' => 0, 'hide_empty' => true, 'exclude' => 13, ); // products categories array $products = array( 'tax_query' => array( array( 'taxonomy' => $taxonomy, 'terms' => get_terms($taxonomy, $args) )) ); ?>
Loop must output each product/category name, link and featured image. I’m using Category Images plugin to output category featured image.
Output should look like this:
1. A (is_post)
2. B (is_term)
3. C (is_post)
4. D (is_post)
5. E (is_term)
6. F (is_term)
- The topic ‘Ordering Posts and Terms in ASC order’ is closed to new replies.