Adding a favorite/save button using JQuery

2k views Asked by At

I've searched quite a bit, but I've been unable to find an answer to this question. I need to create a 'favorite' or 'save' button on each of the posts on my Wordpress site that will save the selected posts for later. It seems like a pretty standard feature on sites like Ebay, Autotrader, etc.

I think I should be able to accomplish this with JQuery, but I've been unable to find much documentation. I've referred to these other topics:

Favorite and unfavorite button in Jquery is not working

jQuery: Making a Favorite button with function?

But they refer to the button's visuals rather than the actual function. I had thought about adding the post-ids to an encoded array within a cookie, but I'm unsure how to do this. Could someone please point me in the right direction? Thank you!

1

There are 1 answers

1
Glenn Geiger On BEST ANSWER

I see you asked this question last summer, but I've gone through this and wanted to help.

There's a difference between (1) creating an account with a website, and then signing in to see your favorites which would likely be records saved in a database. And (2) using cookies or local storage to keep your favorites on that computer, which would allow users to add items to their favorites and see them again when they return. No account required.

I ended up using simpleCart.js which can provide the same results if you make some modifications. Have a look at their demo and you'll see how it could be used to save favorites without creating an account and signing in.

Hope this helps someone.