• 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)
  • 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.

    Thread Starter Iperdesign_IT

    (@iperdesign_it)

    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.

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

    Thread Starter Iperdesign_IT

    (@iperdesign_it)

    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 ===

    Thread Starter Iperdesign_IT

    (@iperdesign_it)

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

    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.