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.

Ok, I've been frustrated about this one:

I've got a category page with the Title + Description of the title. Under it I would like to show all the (custom post type, 'blog') posts related with this category and under it related posts of custom post type 'apps'. When applying the following code it only generates all 'blog' topics with all categories (instead of only the current i'm viewing).

I have this for now:

<?php query_posts( array( 'numberposts' => 5, 'category' => 9, 'post_type' => 'blog' ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

When using:

 <?php if (have_posts()) : ?>
   <?php while (have_posts()) : the_post(); ?>

Does anyone know how I can only show all related posts of this category with custom post type 'blog' ?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It is 'cat', not 'category'.

query_posts( array( 'numberposts' => 5, 'cat' => 9, 'post_type' => 'blog' ) );

Also, be aware the query_posts alters the main page query. Unless you specifically intend to do that, and need to do it, use get_posts or make a new WP_Query object. And if you do have to use query_posts reset the query when you are done-- wp_reset_query. This is all right there in the Codex.

share|improve this answer
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.