If you have a View where you would like users to be able to select specific entries to "like" and add to their list of favorites, follow the directions below to set this up. See an example of a Add to Favorites/Like button. This will only work for logged-in users.
Create Add to Favorites / Like Button Form
- Create a form titled "Add to Favorites". Add a Dynamic field and UserID field.
- In the Dynamic field, set it up to load options from the form that is being used in your main View and select the title or name field if you have one; if not, any other field is fine. Display as a dropdown with Visibility set to Administrator.
- Add [get param=entry] as the dynamic default value. This field will be used to grab the ID of each entry that users "like".
- If you would like to prevent users from "liking" the same entry multiple times, add this code to your theme functions.php file or your own plugin. Make sure to change 125 (in the code example) to the ID of your Dynamic field.
- In the Settings for the Add to Favorites form, do the following:
- Select "Redirect to URL" and leave the URL box blank
- Select "Submit this form with AJAX"
- Select "Only logged-in users can see and submit this form"
- Select "Allow logged-in users to edit their own previous responses"
- Change the Submit Button Text to "Add to favorites" or any other text.
- Go into edit your main View.
- Make sure the View is set to dynamic and the parameter name says 'entry'. If you already have a parameter name that you don't want to change, you could add another parameter to your detail link so it looks like this: [detaillink]&entry=[id].
- In the dynamic content, insert your "Add to Favorites" form like this:
[formidable id=31 minimize=1]
Display List of Users Who Favorited an Entry
If you would like to see a list of users who have "liked" each listing, follow the instructions below.
- Create a View for the "Add to Favorites" form.
- Set it to display All Entries.
- Put this in the content:
<div id="frm_container_[id]"> [981 show="display_name"][deletelink label="Remove from Favorites" prefix="frm_container_"] </div>
Change '981' to the ID of your userID field.
- Add a filter in the Advanced Settings at the bottom that sets your Dynamic field equal to [get param=entry].
- Go into edit your main View and in the dynamic content, insert your new View you have just created.
Show a User Their Favorite Entries
If you want your users to be able to see all the entries they have "favorited", follow, these instructions below.
- Create a View called "Favorite Listings" that uses entries from the "Add to Favorites" form.
- Set it to display All Entries.
- Add any content you would like. If you want to add a "Remove from Favorites" link, add an opening div and closing div around the content with a deletelink included so it will look something like this:
<div id="frm_container_[id]"> Your content here [deletelink label="Remove from favorites" prefix="frm_container_"] </div>
- Add a filter in the Advanced Settings at the bottom that says 'UserID is equal to current_user'.