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. 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 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 form Settings for the Add to Favorites form, do the following:
- In the Confirmation action, set up Redirect to URL and leave the URL box blank
- In the General Settings, select Submit this form with AJAX
- In the Form Permissions, select Limit form visibility and choose Logged-in Users from the dropdown.
- Select the Allow front-end editing of entries checkbox and set Logged-in users as the role required to edit one's own entries.
- In the Buttons, change the Submit Button Text to Add to favorites or any other text.
- Go into edit your main View.
-
Make sure that you have created a Detail Page. In the View builder settings, go to the Advanced Settings section and set the Detail Page Slug to 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]
-
Make sure that you have created a Detail Page. In the View builder settings, go to the Advanced Settings section and set the Detail Page Slug to 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].
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'.