Arrays start from 0, meaning if you want the latest 2, you want to stop when the array key (the index of the array item) reaches 1. So you have 0, and 1. The API automatically orders by newest first, so we just need to tell it when to stop!
In the code above, simply change if ($key == 2){ break; } to if ($key == 1){ break; }
Hope that helps :) but let me know if you have anymore questions, or it doesn't make sense.
do we know how we can view the documentation for this API, in terms of query params and such. I'd like to filter out any article which has been archived, or is in Draft format. As when i hit the api, it seems it is returning archived posts aswell.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Absolutely!
Arrays start from 0, meaning if you want the latest 2, you want to stop when the array key (the index of the array item) reaches 1. So you have 0, and 1. The API automatically orders by newest first, so we just need to tell it when to stop!
In the code above, simply change
if ($key == 2){ break; }
toif ($key == 1){ break; }
Hope that helps :) but let me know if you have anymore questions, or it doesn't make sense.
do we know how we can view the documentation for this API, in terms of query params and such. I'd like to filter out any article which has been archived, or is in Draft format. As when i hit the api, it seems it is returning archived posts aswell.