Need Help regarding to using the WP-Rest-Api (Random Quote Generator)

Need Help regarding to using the WP-Rest-Api (Random Quote Generator)
0

#1

Codepen: http://codepen.io/tstusr/pen/MJBNKR

I’m using the QuotesDesign API V4 in order to get random quotes. My code is able to get a quote from the API but fails to get a random quote with each button click.

In the QuotesDesign page, they have an example which uses the .shift() method which if I understand correctly removes the first element of an array. Shouldn’t this be responsible for getting a random quote each time? If so, what am I doing incorrectly?

Also, this CSS Tricks article they explain that using filter[orderby]=rand in the URL should get you a random quote, which I’m trying to do but doesn’t seem to work.

What’s my best course of action here? I’m not sure what I should be doing to make my code work as intended.


#2

You need to set request with no cache. Right now it is loading the same quote over and over.

Look up how to reset cache in Ajax. There is a method that you can use before the call.

Hope this helps


#3

Thanks a lot. Learned a new thing.

I updated the codepen and it works now :slight_smile: