Support » Fixing WordPress » get_posts with numberposts is not working

  • Goodmorning all,

    I have this problem: i cant set the number of posts to show using the function get_posts.

    Actually

    get_posts(array('numberposts'=>(int)$posts))

    will return all posts into the database without the limit written into the parameter ‘numberposts’. Is it a problem of the new WordPress or am i the dumb ^^” ?

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi

    (@esmi)

    Forum Moderator

    Where’s the $posts variable coming from? I’d suggest that you change the name of the variable to avoid any conflicts and ensure that it an integer before you feed it into the get_posts arguments.

    Where’s the $posts variable coming from? I’d suggest that you change the name of the variable to avoid any conflicts and ensure that it an integer before you feed it into the get_posts arguments.

    I changed the name of that variable into $posts_to_show, and still nothing. By the way that variable come from an input text inside a widget and it is store into $istance.

    esmi

    (@esmi)

    Forum Moderator

    Try echoing $istance and $posts_to_show out onto the page to check that they are being populated correctly.

    I echoed both Instance and Post_to_show… still nothing: they are both populated. I tried to echo the entire args array to see if the variable was “corrupted”, but it was not “corrupted”. I’ll try with ===

    I just used === and it returned true… still nothing happened 🙁

    esmi

    (@esmi)

    Forum Moderator

    Try:

    $posts_to_show = int($instance);
    get_posts(array('numberposts'=>$posts_to_show )
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘get_posts with numberposts is not working’ is closed to new replies.