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>' ); ?>


1 Answer 1


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:

beware lurker, this code is severely outdated

  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(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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