Trouble with custom post types and query
I’m 90% to where I want to be. The page in question is here:
So far, I’ve queried my custom post type, and have it listing by parent category. I want it to list alphabetically. The problem I’m having is that it is sorting within the parent by child category… So it’s not a fully alphabetical list.
Here is the code I’m using…
<?php $args = array( 'orderby' => 'name', 'parent' => 0, 'order' => 'ASC', 'hide_empty' => 1, 'taxonomy' => 'category', //change this to any taxonomy ); foreach (get_categories($args) as $tax) : $args = array( 'post_type' => 'dirlisting', //change to your post_type 'posts_per_page' => -1, 'orderby' => 'name', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'category', //change this to any taxonomy 'field' => 'name', 'terms' => $tax->slug, 'include_children' => false ) ) ); if (get_posts($args)) : ?> <h2><?php echo $tax->name; ?></h2> <ul> <?php foreach(get_posts($args) as $p) : ?> <li><a href="<?php echo get_permalink($p); ?>"><?php echo $p->post_title; ?></a></li> <?php endforeach; ?> </ul> <?php endif; endforeach; ?>
Any help would be greatly appreciated. I just want everything in the parent category to be alphabetical, regardless of child.
- The topic ‘Trouble with custom post types and query’ is closed to new replies.