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

  • Home
  • SEARCH
  • 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 8126231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:05:05+00:00 2026-06-06T07:05:05+00:00

I want to query posts in WordPress by ID range. For example query posts

  • 0

I want to query posts in WordPress by ID range. For example query posts that have ID between 9 – 40. Or get posts that have IDs greater than 9 (ID>9).
How can I specified this type of query in WordPress?
Thanks a lot.

  • 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-06T07:05:06+00:00Added an answer on June 6, 2026 at 7:05 am

    Try this filter, just paste this function in your functions.php

    function filter_by_id($where = '')
    {
        $where .= " AND ID > 50 AND ID < 100";
        return $where;
    }
    

    And in your template file

    add_filter( 'posts_where', 'filter_by_id');
    $args=array(...);
    $my_post = new WP_Query($args);
    while ( $my_post->have_posts() ) : $my_post->the_post();
        // your code
    endwhile;
    remove_filter('posts_where' , 'filter_by_id');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well I have a wordpress loop in wich I want to query posts from
I want to display total number of user who only have posts at Wordpress.
in wordpress i have a query where it queries specific posts. <div id=container-> <?php
I want my WordPress blog to have a page called music. On that page
Hello this is my query. I want to show the titles of posts that
I'm trying to get a custom query going in wordpress. Basically, I want to
I have a page on wordpress where i want to display 10 random posts.
I want to have a page that shows all posts, separated by category. The
i want query a file xml with linq, i want get all descendat of
I want to query the server to see if the date is different than

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.