Skip Navigation

[Resolved] Favorites view + conditional button on post (add to / remove from favorite list)

This thread is resolved. Here is a description of the problem and solution.

Problem: I want my Users to be able to select favorite posts by clicking a button on the single post page that toggles a favorite status.

Solution: Use the cred_save_data function to update a custom field that stores user favorites, or implement a 3rd-party favorites plugin.

50% of people find this useful.

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 7 replies, has 2 voices.

Last updated by Charles 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#555715

Support,

Is it possible to create a conditional button (or maybe even a toggle switch?) in a post body that would allow a user to add a post to his/her favorites list and conditionally display remove the post from the post page?

How would I go about creating a view to display the favorites?

Here is where the favorites view would be displayed: hidden link

Thanks,
Chuck

#555729

Multiple Users may have access to the same Messages shown in this View, so you need the ability to save a "favorite" status for each User, for each Message. Do you agree?

#555762

The messages received and messages sent tabs (shown in the screenshot above) already have their own views, which are conditional to the logged in user.

I assume the favorites view would be unique to each user, but it would be nothing more than displaying the featured post's thumbnail, link to the post and some details from the post (price, mileage, etc.

This could be compared to an eBay watch list and the ability to watch an item when viewing it's post.

#555800

Oh okay, so favorite listing posts, not favorite messages. Got it. You can accomplish this with a CRED edit form and a repeating custom field assigned to the listing post type. The custom field will store the User ID of each User who has selected this listing as a "favorite".
- Add a custom repeating "number" field in the listing post type.
- Create a form that edits the listing post type
- Remove all the inputs from this form except the submit button
- Place the edit form in the Content Template for this post type, so it appears on every post
- Use the cred_save_data hook to add the User's ID to the repeating field when the form is submitted
- Filter your Favorites View by this custom field, and show only posts where the custom field value includes the current logged-in user's ID
- Once that works, you can make modifications in the cred_save_data hook and the form that will allow your users to un-favorite a post by deleting their ID from the custom field, if you think this is necessary. The Submit button can include conditional text depending on whether or not the post is already favorited, and the cred_save_data hook can be set up to toggle that custom field value depending on the current favorite status.

#556285

Christian,

Working through this now. I'm confused with " - Use the cred_save_data hook to add the User's ID to the repeating field when<b> the form is submitted</b>"

So with this method, users will have to submit a form in order to add a motorcycle to their favorites list?

Screenshot 1: hidden link
Screenshot 2: hidden link

In screen shot one, note the "add to watchlist" button under the make an offer button. Once that is clicked a message appears, shown in screenshot 2. The used only has to click a button and only the reloads and displays the message showing go to list or remove options. This is what I would be trying to duplicate.

Thanks,

Thanks,
Chuck

#556298

So with this method, users will have to submit a form in order to add a motorcycle to their favorites list?
Yes, that's correct. We need to add the User's ID into a repeating custom field on the motorcycle post. This is how we will know which Users have favorited this listing. To add the ID, we must edit the listing post, and we will use an Edit Motorcycle CRED form to accomplish that. It will look like a simple button and work like the Add to Watchlist button, because you will remove all the inputs and text from this form. The only thing that will be displayed is the submit button, which you can style however you would like - it can say "Add to Favorites". When the user clicks the button, the form submits, triggering the cred_save_data function.

In the cred_save_data hook you will add the User's ID to the repeating custom field in the motorcycle listing post using update_post_meta(). After submission you can display a message to your user, using the submission settings of the CRED form, stating that the item has been added to their favorites list. If the favorites list is shown on the same page, you can refresh the page and the favorites list will update.

#556315

Going to try this plugin: hidden link

Will keep you posted.

Thanks,
Chuck

#556318

It worked, piece of cake. Just needs styling.

See above title: hidden link
See under favorites: hidden link

Cheers,
Chuck