How to get a wordpress post randomly

Asked

Viewed 29 times

-1

Good, I want to search for a random post of the articles but it always gives me the same article.

wp-json/wp/v2/fatos_random? filter[orderby]=rand&per_page=1

Thanks for the help

1 answer

0

You need to use the Rand() function, stating the parameters you need... the example below lists a single item ranging from 1 to 15. Then only link Rand to its variable $per_page

rand(1, 15);

Source documentation: https://www.php.net/manual/en/function.rand.php

  • But there’s no way to do it through the URL if I don’t have to load all the facts and only then choose one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.