1

i have a custom query to display relation with posts (post 2 post plugin)

my existing code display : foreach terms as terms

i need to display for each Parents Display Child then Posts Titles

Example:

x Portfolio (Parent)

-Graphic Design (Child)

  • Post 1

-Webdesign (Child)

  • Post A

  • Post B

  • Post C

-Video Editing (Child)

  • Post F

  • Post K

x Profile (Parent)

-Clients (Child)

  • Post zz

-Friends (Child)

  • Post FF

  • Post ZK

Here is My Code :

<?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(). ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.