Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called 'seasons' and in there i have 3 categories (summer,winter and spring.)

I want to show 10 random post from the winter category on a page.

Please help.

share|improve this question

2 Answers 2

WP_Query is the solution to your problem.

Go through the available parameters. Just add a query and a loop in your page template and you are good to go.


$args = array(
'category_name' => 'winter',
'orderby' => 'rand',
'posts_per_page' => 10

$query = new WP_Query( $args );

The loop starts here:

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

and ends here:

<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
share|improve this answer

You need to add the custom post type in the $args array in the code above by Rohit:

$args = array(
    'orderby' => 'rand',
    'posts_per_page' => 10,
    'post_type' => 'seasons', //ADD THIS
    'category_name' => 'winter'
share|improve this answer

Your Answer


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.