Iperdesign_IT
Member
Posted 8 months 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 ^^" ?
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.
Iperdesign_IT
Member
Posted 8 months 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.
Try echoing $istance and $posts_to_show out onto the page to check that they are being populated correctly.
Iperdesign_IT
Member
Posted 8 months 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 ===
Iperdesign_IT
Member
Posted 8 months ago #
I just used === and it returned true... still nothing happened :(
Try:
$posts_to_show = int($instance);
get_posts(array('numberposts'=>$posts_to_show )