I have a code, i used to call a particular category in my post page footer and i have specified the number of posts to display but its showing all the posts from that category.

here are the codes

<?php query_posts('category_name=tech&order=dsc&showposts=12'); ?>

and <?php query_posts('cat=438'.'&showposts=7'); ?>

any help please, i really need the post to be five. As for loop, am using my default loop to get my preferred design.


  • 1
    I would strongly advise against using query_posts, it might appear simpler to use than WP_Query, but it can cause problems such as these where the query replacement it makes interferes with other logic further down the page
    – Tom J Nowell
    Apr 1, 2017 at 15:45
  • do you mean i should replace query_posts with WP_QUERY? Am a newbie i don't really know how these things work or maybe you could write the full code for me without including the loop. Thanks Apr 1, 2017 at 20:42
  • you'll never learn if you don't try yourself, but there are huge numbers of examples on how to use WP_Query on this site and in the Core WP docs. If you're still stuck, ask a question on this site
    – Tom J Nowell
    Apr 2, 2017 at 18:10

2 Answers 2


If you need the number of posts in the query args then use posts_per_page, since posts_per_page has a default value of 10, it will always display 10 posts, if you wish to see all the posts, as in, there should not be any limit then choose its value to be -1 and use it like this

    'posts_per_page'=> '-1', 

It says here that showposts was replaced by posts_per_page. Try using it instead.

  • thanks for your response but i've tried that before. I don't know if i should add something in functions or something Apr 1, 2017 at 20:45
  • @TarrmiedeMan I mean simply to put posts_per_page instead of showposts in the code that you provided.
    – Nikolay
    Apr 2, 2017 at 6:57
  • 1
    @TarrmiedeMan Can you show me the whole PHP code that you are using so I can test it?
    – Nikolay
    Apr 2, 2017 at 13:27

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.