Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //get all children of category "MyCat", then display posts in each cat
- $taxonomy = 'category';
- $param_type = 'category__in';
- $cat_id = get_cat_ID('MyCat');
- $term_args=array(
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'child_of' => $cat_id
- );
- $terms = get_terms($taxonomy,$term_args);
- if ($terms) {
- foreach( $terms as $term ) {
- $args=array(
- "$param_type" => array($term->term_id),
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'posts_per_page' => -1,
- 'caller_get_posts'=> 1
- );
- $my_query = null;
- $my_query = new WP_Query($args);
- if( $my_query->have_posts() ) {
- echo '<ul>
- <li class="listheader"><h2>'.$term->name.'</h2></li>';
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
- (my post content is here)
- <?php
- endwhile;
- } echo '</ul>';
- }
- }
- wp_reset_query(); // Restore global post data stomped by the_post().
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement