1

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.

thanks

  • 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 '17 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 – Tarrmie de Man Apr 1 '17 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 '17 at 18:10
1

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

$args=array( 
    'post_type'=>'page',
    'posts_per_page'=> '-1', 
); 
0

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 – Tarrmie de Man Apr 1 '17 at 20:45
  • @TarrmiedeMan I mean simply to put posts_per_page instead of showposts in the code that you provided. – Nikolay Apr 2 '17 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 '17 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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