remove duplicates from loop
-
in my wordpress site, i have categories like this :
Parent Category 1
– Sub Category 1
– Title
– Title
– Sub Category 2
– Title
– Title
Parent Category 2
– Sub Category 1
– Title
– Title
– Sub Category 2
– Title
– Title
Category 3
– Title
– TitleI want to display post, for each term as term > display post
but i don’t want to display Parent Category , i want a loop to be like this:
– Sub Category 1
– Title
– Title
– Sub Category 2
– Title
– Titlesometimes posts are associated with 2 category, how to remove duplicates ?
<?php $do_not_duplicate = array(); //get all categories then display all posts in each term $taxonomy = 'category'; $param_type = 'category__in'; $term_args=array( ); $terms = get_terms($taxonomy,$term_args); if ($terms) { foreach( $terms as $term ) { $args=array( "$param_type" => array($term->term_id), 'connected_type' => 'posts_to_invitations', 'connected_items' => get_queried_object(), 'nopaging' => true, 'post_type' => 'post', 'post_status' => 'publish,draft', 'posts_per_page' => -1, 'post__not_in' => $do_not_duplicate, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { $do_not_duplicate[] = get_the_ID(); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <tr> <td><?php include (TEMPLATEPATH . '/contactfullname.php'); ?></td> <td><?php echo get_post_meta($post->ID, 'ecpt_position', true); ?></td> <td><?php echo p2p_get_meta( get_post()->p2p_id, 'table', true ); ?></td> <td><?php echo ' ' .$term->name;?></td> <td><?php echo p2p_get_meta( get_post()->p2p_id, 'confirmation', true ); ?></td> </tr> <?php endwhile; ?> <?php } } } wp_reset_query(); // Restore global post data stomped by the_post(). ?>
The topic ‘remove duplicates from loop’ is closed to new replies.