title: How to loop through the custom post type once you have added to an existing query
body: <p>I am a bit stuck with a project and I would appreciate if someone could help me with that one.
  I've searched for some references everywhere (firstly of course here) and I only could find bits and pieces of what I need.</p>
  
  <p>I need to end up with the following structure:</p>
  
  <pre><code>&lt;!--LOOP 1 -  WORD PRESS PARENT PAGES--&gt;
  &lt;div id="post-parent1-name"&gt;...&lt;/div&gt;
  
  &lt;div id="post-parent2-name"&gt;
  
      &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
      &lt;div class='post-content'&gt;&lt;?php the_content(); ?&gt;&lt;/div&gt;
  
      &lt;!--LOOP 2 -  WORD PRESS CHILDREN PAGES--&gt;
      &lt;div id="post-child1-name"&gt;...&lt;/div&gt;
  
      &lt;div id="post-child2-name"&gt;
          &lt;h3&gt;&lt;?php the_title(); ?&gt;&lt;/h3&gt;  
  
          &lt;!--LOOP 3 - WORD PRESS CUSTOM POST TYPE--&gt;
          &lt;div id="custom-post-type-name"&gt;
              &lt;h4&gt;&lt;?php the_title(); ?&gt;&lt;/h4&gt;
              &lt;div class='post-content'&gt;&lt;?php the_content(); ?&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div id="post-child3-name"&gt;...&lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;div id="post-parent3-name"&gt;...&lt;/div&gt;
  &lt;div id="post-parent4-name"&gt;...&lt;/div&gt;
  </code></pre>
  
  <p>I've used the following filter in my functions.php to add the custom post type to the query:</p>
  
  <pre><code>&lt;?php
   function insert_post( $query ) {
   if ( $post-&gt;post_name == 'my_parent_post_name' &amp;&amp; $query-&gt;is_main_query() )
   $query-&gt;set( 'post_type', array( 'post', 'my_custom_post_type') );
   return $query;
   }
   add_filter( 'pre_get_posts', 'insert_post' );
  ?&gt;
  </code></pre>
  
  <p>I've managed to get the first and the second one to work fine however I could not figure out how to get the third one to work <strong>(which is my custom post type)</strong> in order to bring me the title, content and thumbnail respectively.</p>
  
  <p>Sorry guys, I know that looks a bit confusing however I hope that makes sense.</p>
  
  <p>Cheers,
  Doug.</p>