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 am having no luck with querying a custom post type taxonomy from an array in theme options.

My full code is below, would be grateful for some feedback to get it working correctly as I cannot get this to work.

// Pull all the custom taxonomies into an array
// options.php

$options_taxonomies = array();
$taxonomies_terms_obj = get_terms('portfolio_category');
  foreach ($taxonomies_terms_obj as $taxonomy) {
$options_taxonomies[$taxonomy->term_id] = $taxonomy->name;
}

// Select a Featured Homepage Category

 $options[] = array(
'name' => __('Featured Homepage Category', 'options_framework_theme'),
'desc' => __('Choose a category to feature on your homepage.', 'options_framework_theme'),
'id' => 'homepage_feature',
'type' => 'select',
'options' => $options_taxonomies);
 }

// WP_Query and Loop
// front-page.php

<?php 

$num_cols = 3; // set the number of columns here

if ( function_exists( 'of_get_option' ) ) :

   $args = array(
   'posts_per_page' => 3,
    'tax_query' => array(
     array(
        'taxonomy' => 'portfolio',
        'field' => 'id',
        'terms' => of_get_option( 'homepage_feature' )
         )
     )
  );

  $my_qry = new WP_Query($args); 

  if (have_posts()) :
  for ( $i=1 ; $i <= $num_cols; $i++ ) :
  echo '<div id="col-'.$i.'" class="four columns entry-thumb">';
  $counter = $num_cols + 1 - $i;
  while (have_posts()) : the_post();
      if( $counter%$num_cols == 0 ) : ?>
      <!-- core post area; title, content, thumbnails, postmeta, etc -->
 <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail-home', array('class' => 'image-fade')); ?></a>
<p class="entry-title-home"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
  <?php endif;
  $counter++;
endwhile;
rewind_posts();
    echo '</div>'; //closes the column div
endfor;
else:
   echo '<div class="four columns">Please create a post.</div>';
  endif;
  endif; rewind_posts(); wp_reset_query(); 
?>
share|improve this question
    
You should not have duplicated this question: wordpress.stackexchange.com/questions/85572/… –  s_ha_dum Feb 13 '13 at 14:50
add comment

1 Answer

up vote 0 down vote accepted

You create a new query and assign it to $my_qry, but you never loop over those results. See the codex page for WP_Query, the loop has to reference your new query object:

$my_qry = new WP_Query($args);
if ( $my_qry->have_posts() ) :
    while ( $my_qry->have_posts() ) :
        $my_qry->the_post();
        // etc..
    endwhile;
endif;
share|improve this answer
    
Thank you this worked a treat. :) –  Dean McCann Feb 13 '13 at 12:51
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.