Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Basically I have two loops that work seperately but I need information of one of the loops to go into a listing which happens to be in the other loop. This concerns fetching custom taxonomies and custom post types.

Is there a way to combine both into one query? This is what I thought would work: *Notice the brackets I moved from up top to a bit lower? I know this is incorrect, please tell me how I should approach it.

$args=array(
  'public'   => true,
  '_builtin' => false
);
$output = 'names'; // or objects
$operator = 'and';
$taxonomies=get_taxonomies($args,$output,$operator); 
if  ($taxonomies) {
  foreach ($taxonomies  as $taxonomy ) {
    $terms = get_terms($taxonomy, array('hide_empty' => false));
    foreach ( $terms as $term) {
      ?>
            <li><br><a href="#"><input type="checkbox" name="profile[]" value=""><?php echo $term->name; ?> <br/></a></li>
            /*------>Brackets were here<------*/
          </ul>
        </nav>
      </div>
      <div id="main">
        <ul class="listing">
          <?php $args = array(
            'post_type' => 'bedrijf',
            'posts_per_page' => -1,
            'orderby' => 'title',
            'order' => 'ASC'
          );
          $query = new WP_Query( $args );
          if ( $query->have_posts()) :
            while ( $query->have_posts()) :  $query->the_post();
              $title = get_the_title();
              $beginletter = substr(strtoupper($title), 0,1); ?>

              <li id="list" data-filter="<?php echo $term->name; ?>" data-letter="<?php echo $beginletter; ?>"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
              /*----->These are the brackets of the loop above<--------*/    
    }
  }
}
?>    
<?php endwhile; wp_reset_postdata(); endif; ?>
</ul>
</div>
share|improve this question
1  
I made an effort to improve your code formatting, but your code doesn't make sense. For example, you have close tags (HTML) and no start tags and you have started a loop nested inside another one but don't close that loop until after the parent loop closes. –  s_ha_dum Mar 5 at 14:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.