Change query to display for each parent and for each Child
-
hello i have a custom query to display relation with posts (post 2 post plugin)
my existing code display : foreach Categories and Categoriei need to display
for each Parent as Parent
Display Parent Cat Name
for each Parent Child
Display Post Titlehere is my code : https://pastebin.com/xsyFiGV7
<?php //do not show duplicates $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) { $counter = 1; $total_invitations=0; $total_invitees=0; foreach( $terms as $term ) { $args=array( 'parent' => 0, 'orderby'=> 'title', 'order' => 'ASC', 'connected_type' => 'posts_to_invitations', 'connected_items' => get_queried_object(), "$param_type" => array($term->term_id), '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() ) { $cat_invitations=$my_query->found_posts; $cat_invitees=0; $do_not_duplicate[] = get_the_ID(); ?> <tr id="tabelhead"> <td style=" background-color: #bdbdbd;color:#000000"><?php echo $term->name;?></td> </tr> <?php if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); $post_id = get_the_ID(); if (in_array($post_id, $do_not_duplicate)) { continue; // We've already seen this post ID, so skip the rest of the loop } if (p2p_get_meta(get_post()->p2p_id, 'couples', true) == '1') $cat_invitees+= 2; else $cat_invitees++; $do_not_duplicate[] = $post_id; ?> <tr> <td id="name" style="border: 1px !important;" border="1"><?php include (TEMPLATEPATH . '/contactfullname.php'); ?></td> </tr> <?php $counter++; ?> <?php endwhile; $total_invitees+=$cat_invitees; $total_invitations+=$cat_invitations; } ?> <?php } } } wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Change query to display for each parent and for each Child’ is closed to new replies.