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
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?
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.
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.
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
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.
Going to try this plugin: hidden link
Will keep you posted.
Thanks,
Chuck
It worked, piece of cake. Just needs styling.
See above title: hidden link
See under favorites: hidden link
Cheers,
Chuck