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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:36:00+00:00 2026-05-20T02:36:00+00:00

Take a look at this awesome code from John P Bloch. What this code

  • 0

Take a look at this awesome code from John P Bloch. What this code does is:

It looks to see how many posts are going to be displayed by default. If it’s fewer than 20, it grabs the difference (in this case, it should grab 10 posts) and appends them to the current query. Then it recurses through itself to see if it’s still under 20 posts. If so, it continues to run until it hits at least 20 posts.

function my_awesome_post_booster(){
      if(!is_home())
        return;
      global $wp_query;
      if( $wp_query->post_count < 20 ){
        $how_many = 20 - $wp_query->post_count;
        $newposts = get_posts('numberposts='.$how_many);
        $wp_query->posts = array_merge( $wp_query->posts, $newposts );
        $wp_query->post_count += count($newposts);
        my_awesome_post_booster();
      }
    }

    add_action('template_redirect', 'my_awesome_post_booster');

Problem is, it does not recurses throught itself, it does not continue.

Lets say i have 5 posts, the code should repeat them 4 times until it reaches 20. But it doesn’t.

Any ideas why? Ty

P.S. here is my idea, tho not sure how to put it in php.

Lets say i have 5 posts.

$wp_query->post_count will be 5

$how_many = 20 - $wp_query->post_count; will be 15

$newposts = get_posts('numberposts='.$how_many); - will try to get 15 posts, but it can't, cause the blog only has 5!

The scrip thinks he pulled 15, even tho he didn't.

The idea is to divide $how_many to the actual number of posts which is 5, but get an even number…. Like this:

$how_many = 20 - $wp_query->post_count; will be 15
divide $how_many with $wp_query->post_count;
make sure it's an even number, lets say 3,33, makes it 3... 
 $newposts = get_posts('numberposts='.$that_numer);

What do u think? 🙂 Can i put this into php?

  • 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-20T02:36:01+00:00Added an answer on May 20, 2026 at 2:36 am

    The function is calling itself over and over but has no default return! This may not be causing your issues here, but it will certainly cause memory leaks if its used too much! I would consider adding a return true to the very bottom of the function otherwise each instance will remain in memory, when it shouldn’t

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

Sidebar

Related Questions

Take a look at this: http://thebekker.dk/_skole/GFeksamen/ You can see the 2nd menu item show
Take a look at this code: public class Test { public static void main(String...
take a look at this code: $(document).ready(function() { document.getElementById(sliderId).onmousedown = sliderMouseDown; }); function sliderMouseDown()
Take a look at this html page . In Firefox it looks just like
Take a look at this example code, which doesn't work: <?xml version='1.0' encoding='UTF-8' ?>
Take a look at this code : public class Program { [import]IMain Main {get;
Take a look at this piece of code - (NSMutableDictionary *)getUsersFromServer { //here we're
Take a look at this code: Foo &Bar::Copy() { return Bar(); } The class
Take a look at this jsFiddle Code also listed below: window.MyView = Backbone.View.extend({ ticks:
take a look at this button In Chrome this looks fine but switching to

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.