WordPress.org

Ready to get started?Download WordPress

Forums

get_posts with numberposts is not working (7 posts)

  1. Iperdesign_IT
    Member
    Posted 2 years ago #

    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 ^^" ?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    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.

  3. Iperdesign_IT
    Member
    Posted 2 years ago #

    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.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

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

  5. Iperdesign_IT
    Member
    Posted 2 years ago #

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

  6. Iperdesign_IT
    Member
    Posted 2 years ago #

    I just used === and it returned true... still nothing happened :(

  7. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try:

    $posts_to_show = int($instance);
    get_posts(array('numberposts'=>$posts_to_show )

Topic Closed

This topic has been closed to new replies.

About this Topic