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 7857289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:59:42+00:00 2026-06-02T20:59:42+00:00

I want to get latest two posts. I’m trying to use following query, but

  • 0

I want to get latest two posts. I’m trying to use following query, but for some strange reasons it is returning me one extra post (total 3 posts instead of 2). Similarly if i put 3 in the query, it will return 4 posts.
Why this is happening and how can I fix it? Thanks.

<?php query_posts( 'posts_per_page=2' ); ?>
    <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
            <?php the_title(); ?>                       
        <?php endwhile; endif;?>
    <?php wp_reset_query();?>
  • 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-06-02T20:59:43+00:00Added an answer on June 2, 2026 at 8:59 pm

    Do this:

    <?php $my_query = new WP_Query('category_name=mycatname&showposts=2'); ?>
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <?php the_title(); ?>
    
    <?php endwhile; ?>
    

    No need for wp_reset_query; this loop can be used multiple times in a template.

    Delete the category_name=mycatname& if you don’t need the category name.

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

Sidebar

Related Questions

I want to get two latest words from a string variable. Total number of
I want to get the latest 5 messages in the inbox. To get the
I want to get the latest revision number of the SVN database using SVNKIT.
What I want: get a xml from the AppData to use What I code
i want query a file xml with linq, i want get all descendat of
Currently I found two ways to get the latest version - in Visual Studio
I have a two tables as authors and articles. I want to get list
I'm running a query to get the 5 latest News items. In my template,
I am trying to get this jGrowl working but I am not having any
I'm trying to get the new HornetQ 2.3.0.alpha replication running, on two different hosts.

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.