Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:07:56+00:00 2026-05-28T03:07:56+00:00

I have a page on wordpress where i want to display 10 random posts.

  • 0

I have a page on wordpress where i want to display 10 random posts. It is working using that code:

    <?php if ( have_posts() ) : ?>

            <?php twentyeleven_content_nav( 'nav-above' ); ?>

            <?php /* Start the Loop */ 
            query_posts( 'orderby=rand&posts_per_page=10' );
            ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', get_post_format() ); ?>

            <?php endwhile; ?>
 [...]

I want to disable pagination on that page, if i disable it using nopaging=true, all posts will be displayed. How to set a limit while limiting the number of posts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:07:56+00:00Added an answer on May 28, 2026 at 3:07 am

    first of all, you should put the call to query_posts outside the if statement for have_posts.

    In short, you’ve essentially already ‘disabled’ pagination with the query_posts call. You simply haven’t removed the links (the twentyeleven_content_navs), that allow users to ‘paginate’. In fact, the users wouldn’t be changes pages at all really. Let me explain…

    When the page loads, 10 posts are selected at random. At the moment, links display (beause WordPress knows that there are more than 10 posts that could be shown, and as far as I’m aware there is not a way of telling it otherwise, unless you use get_posts instead).

    Anyway, if a user clicks to the next page, the page loads again – but in fact you query over-rides their ‘page-2’ request, and shows the first 10 random posts. But these posts won’t be the same as the original, as it’s random.

    In short, the pagination links are, in effect, simply refreshing the page, revealing 10 new random posts: despite the fact the url suggests they are navigating through pages.

    In summary, just remove the links!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page within wordpress that I want to password protect via a
I want my WordPress blog to have a page called music. On that page
I have a page in Wordpress that loops posts in a specific category. In
I have a wordpress-generated page where I need some posts (in a specific category)
I have a PHP page, in Wordpress. When I add a inline Thickbox to
I have configured WordPress to display a static front page as described here: http://codex.wordpress.org/Settings_Reading_SubPanel#Reading_Settings
I have an admin page for a WordPress plugin that, thanks to the stackoverflow
I edited my wordpress page to only display posts from certain categories. This works,
How to selectively display pages on sidebar? I have some pages that i want
I have an idea for my wordpress blog. I want to have a page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.