0

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

1 Answer 1

2

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.

Your Answer

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

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