Home » Wordpress » How do I get ALL posts in a category with WordPress?

How do I get ALL posts in a category with WordPress?

Posted by: admin November 30, 2017 Leave a comment

Questions:

This works pretty good except it is limited to 10 posts since my blog is set to show 10 posts maximum.

   $featured_query = new WP_Query('cat=3');

        while( $featured_query->have_posts() ){
            $featured_query->the_post();
            $postcount++;
            ...

How can I override that setting and get ALL posts in that category regardless of the maximum posts setting?

Answers:

Use showposts=-1. This will override the defaults posts setting. Per this: http://codex.wordpress.org/Template_Tags/query_posts#Post_.26_Page_Parameters

Questions:
Answers:

Does query_posts(‘cat=3’) do what you want?

Questions:
Answers:

This is best way to do the list of a particular category..

>  $catPost = get_posts(get_cat_ID("NameOfTheCategory"));

> foreach ($catPost as $post) : setup_postdata($post); ?>
>        <div>
>              <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
>              <p><?php the_content(); ?></p>
>        </div> <?php  endforeach;?>

Thanks
MrPhpGuru