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 can get custom posts to display on my site. However, I want to filter the posts by category.

The custom posts are displaying on this page: http://www.africanhealthleadership.org/resources/toolkit/

The custom posts are the tools i.e. Desk Research and Assessment Tool

Under Preparation, I only want to show Desk Research. However ALL the tools are displaying under Preparation.

I used this code to get the tools to display. Clearly category_name is not working, but I am not sure how to fix. Thank you for any help.

<?php $loop = new WP_Query( array( 'post_type' => 'portfolio', 'category_name' => 'preparation' ) ); ?>

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

<?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>

`

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Can you be more specific?do you mean custom post type or custom query?

AFAIK when using custom post type you cannot directly use category_name since your post are treated in different way. You have to add custom taxonomies in register_post_type and then register them with register_taxonomy()

note: please correct me if my statement above is wrong, I'm not go deep with custom post type, at least for now.

say you have custom post type named portfolio, custom taxonomy named toolkit with following categories:

  1. preparation
  2. assessment
  3. leadership
  4. innovation

and you want to show all post in preparation:

<?php
  query_posts( array( 'post_type' => 'portfolio', 'toolkit' => 'preparation' ) );
  //the loop start here
  if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
  <h3><?php the_title(); ?></h3>
  <?php the_content(); ?>
<?php endwhile; endif; wp_reset_query(); ?>
share|improve this answer
    
That's exactly it, thank you!!!!!!!!!!!!!!!!!! –  Jeff Tancil Oct 13 '10 at 17:12

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.