WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can you please let me know why this code is not listing Custom Post Types?

<?php 
$loop = new WP_Query(
              array(
                'post_type' => 'product',
                'tax_query' => array(
                    array(
                        'taxonomy' => 'genre',
                        'field' => 'name',
                        'terms' => 'ne',
                        'order' => 'ASC',
                    )
                ),
                'posts_per_page' => 10
              )
         );
?>
<?php 
if ( $loop->have_posts() ) :
echo '<ul>';
 while ( $loop->have_posts()) : $loop->the_post();
 $custom = get_post_custom($post->ID);
 echo '<li>'.the_title().'</li>';
endwhile;
echo '</ul>';
endif;
?>

Thanks

share|improve this question
up vote 2 down vote accepted

If you want to sort the custom post type 'product' by title, please try:

 array( 'post_type'       => 'product',
        'posts_per_page'  => 10, 
        'orderby'         => 'title',
        'order'           => 'ASC',
        'tax_query' => array(
             array( 'taxonomy' => 'genre',
                   'field'     => 'slug',
                   'terms'     => 'ne',
                  )
         )
      )

where 'field' can in general be either 'id' or 'slug' (ref). You can check the available orderby input parameters here.

share|improve this answer
    
Thanks birgre, it is working perfectly now – Behseini May 19 '13 at 15:10

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.