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.

I have a page where it lists the category name with it's posts under. On this page it only lists the posts that are also in another custom taxonomy. To do so I am using this code which works fine --

<?php
$custom_terms = get_terms('videoscategory');
$other_custom_terms = get_terms('product_category');

foreach ($custom_terms as $custom_term) {
foreach ($other_custom_terms as $other_custom_term) {
    wp_reset_query();
    $args = array('post_type' => 'product', 'orderby' => 'title', 
                'order' => 'asc',
        'tax_query' => array(
  'relation' => 'AND',
'orderby' => 'title', 
                'order' => 'asc',
    array(
        'taxonomy' => 'product_category',
        'field' => 'slug',
        'terms' => $other_custom_term->slug,
'orderby' => 'title', 
                'order' => 'asc',
    ),
            array(
                'taxonomy' => 'videoscategory',
                'field' => 'slug',
                'terms' => $custom_term->slug,
'orderby' => 'title', 
                'order' => 'asc',

            ),
        ),
  );

     $loop = new WP_Query($args);
     if($loop->have_posts()) 
     {
        ?>

        <div class="box <?php echo $custom_term->slug; ?>" style="float:left;width:100%;">
        <h1 style="margin-top:10px;font-size:20px;font-weight:bold;"><?php echo $custom_term->name;?></h1>

      <?php       
      while($loop->have_posts()) : $loop->the_post(); ?>

            <h2><a href="<?php echo get_permalink() ?>"><?php echo get_the_title(); ?></a></h2>
      <?php  endwhile; ?>
      </div>
     <?php   
     }
}
} ?>

And if am currently using the following code to create a dropdown populated with all the categories in my custom taxonomy, which also works fine --

<?php
$terms = get_terms("videoscategory");
 $count = count($terms);
 if ( $count > 0 ){
     echo "<select id='filter-select' style='width: 275px;height: 25px;'>";
echo "<option value='*' data-filter-value='' class='selected'>All items</option>";
     foreach ( $terms as $term ) {
         echo "<option value='.{$term->slug}'>" . $term->name . "</option>";
     }
     echo "</select>";
 }
?>

However I do not want all the categories listed in the dropdown for this page. I am trying to only list the categories that actually show up on this page. So I tried editing my code to list the respective categories but it ends up display a whole bunch of drop downs with 1 category in each of them, and seems to still list all the categories. This is the code I am currently working on for the drop down ---

<?php
$custom_terms = get_terms('videoscategory');
$other_custom_terms = get_terms('product_category');

foreach ($custom_terms as $custom_term) {
foreach ($other_custom_terms as $other_custom_term) {
    wp_reset_query();
    $args = array('post_type' => 'product', 'orderby' => 'title', 
                'order' => 'asc',
        'tax_query' => array(
  'relation' => 'AND',
'orderby' => 'title', 
                'order' => 'asc',
    array(
        'taxonomy' => 'product_category',
        'field' => 'slug',
        'terms' => $other_custom_term->slug,
'orderby' => 'title', 
                'order' => 'asc',
    ),
            array(
                'taxonomy' => 'videoscategory',
                'field' => 'slug',
                'terms' => $custom_term->slug,
'orderby' => 'title', 
                'order' => 'asc',

            ),
        ),
  );

     $loop = new WP_Query($args);
     if($loop->have_posts()) 
     {
        ?>
  <?php       
      while($loop->have_posts()) : $loop->the_post(); ?>

      <select id="filter-select" style="width: 275px;height: 25px;">
<option value="*" data-filter-value="" class="selected">All items</option>
    <option value=".<?php echo $custom_term->slug; ?>"><?php echo $custom_term->name;?></option>
    </select>

      <?php  endwhile; ?>
      </div>
     <?php   
     }
}
} ?>

So far no luck, how can I fix my code to make the dropdown dynamically populate with the categories from the page?

share|improve this question
    
Can anyone help? –  mygm26 Apr 20 '13 at 4:16
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

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.