Skip Navigation

[Resolved] implement favorites system with toolset

This support ticket is created 3 years, 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 61 replies, has 4 voices.

Last updated by simonM-5 3 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#1766877

Hi Jamal

I tested this and cannot seem to "break" it any more, in EN or DE :-).. I'd like to have a go at implementing the same fixes for the Nanny Ads before we close the ticket.

Can we somehow start a new ticket together regarding favouriting of the Ads? I haven't heard anything back from the Favorites plugin author unfortunately, and there has been no response on the WP forum (https://wordpress.org/support/topic/using-favorites-plugin-with-wpml/) either.

We love the simplicity of the Favorites plugin and ideally we'd love it to work in a very similar fashion just replacing it with Toolset/WPML compatible code. Our requirements would be then:
- User should be able to simply click an icon on the Ad to favourite it
- The Ad should be immediately visible as favourited without further saving or clicking, (eg like the current plugin does by flipping between two icons, eg empty heart and full heart)
- We should still be able to use Font Awesome icons with it (I imagine that's a given if using Toolset).
- It must be easy to filter for favourited Ads using the built-in Toolset query filtering in Views, so that it's easy to create a Toolset View of favourited Ads
- It should remain WPML-compatible, so if I favourite an Ad in one language it should be favourited in all languages. I think it may be permissible (or even necessary) here to use custom code to enforce this. (One option might just be to use the existing Favorites plugin and come up with this custom code?)

My thinking to achieve this would be:
- Adding a custom field to the Job Ad and Nanny Ad custom post types to hold the favourited flag
- Use JavaScript or similar to force an immediate save on the post after clicking the favourite icon
- Ensure the flag is propogated to all language duplicates or the original if a duplicate was clicked.

What are your thoughts? Can you split this into a separate ticket?

Best regards
Simon

#1766887

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Simon,

The favorites system will depend on a custom field and a couple of forms.

Here below my suggestion after each of your requirements and features you want to have.

- User should be able to simply click an icon on the Ad to favourite it
Build two forms that will only have the submit button, and using CSS, put an icon on each form's submit button.
One form will be used as "Favorite this", and will make the custom field to favorite. This form will have a "heart" icon for example.
Another form will be used as "unfavorite" and will make the custom field to not-favorite. This form will have a different icon.

- The Ad should be immediately visible as favourited without further saving or clicking, (eg like the current plugin does by flipping between two icons, eg empty heart and full heart)
This will probably need some custom Javascript code. Let's work on it later.

- We should still be able to use Font Awesome icons with it (I imagine that's a given if using Toolset).
Yes, this won't be difficult at all. At least, that's what I think.

- It must be easy to filter for favourited Ads using the built-in Toolset query filtering in Views, so that it's easy to create a Toolset View of favourited Ads
Of course, the query filter will be on the favorite custom field.

- It should remain WPML-compatible, so if I favourite an Ad in one language it should be favourited in all languages. I think it may be permissible (or even necessary) here to use custom code to enforce this. (One option might just be to use the existing Favorites plugin and come up with this custom code?)
This can be a bit tricky. Because, due to WPML way, we'll need to always update the original post, and let WPML synchronize the value of the field to the other language.
We can implement this using a couple of custom code:
- Similarly to our first ticket, one code will check if the current post is a duplicate or original.
- Another code will return the original post ID if the current post is duplicate.
Then depending on the value of custom field for the original post, we'll put either, the favorite form or the unfavorite form, but we'll scope the form to the original post. We'll use a content template and the "item" argument to scope the content template to the original post. The content template will contain the form(s). We'll either use two content templates for the two forms, or we can use one content template and put the condition(is favorite or no) and the forms inside of it.

I hope this gives an idea of how to implement this favorites system. Let me know if you have any questions.

Good luck,
Jamal

#1768585

HI Jamal

I started to do the first form and realised that I cannot simply set a flag to 1 or 0 in the custom post types Job Ad and Nanny Ad, because it has to be user-specific. In database terms I'd need to have a table with one column containing the post ID and the other the user ID. Then one would either need to have a third flag field representing the two states favourited/not favourited, or alternatively, if a favourite is removed, the record of the two IDs removed.

Is it better then, to conceptualise as a new Custom Post Type, eg Favourites?

What are your thoughts?

Thanks and regards
Simon

#1769129

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Simon

You are right, I totally missed it, my apologies. The flag should be set per post, per user. I can think of two ways:
- Using custom fields but without Toolset. The custom field can be build using the user ID, for example, "favorite_1" for the user with ID 1.
- With a custom post type, as you suggested. The post type will have a 1-to-many relationship. And the user who favorited the post will get a post(Favorite) created, linked to the post, and for which he is the author. But, this may be more complex as we need to use WPML and get favoriting synced across languages.

Let me think about it a bit and get back to you.

#1770399

HI Jamal

Thanks.

FYI - our site was attacked by a virus and now I am in the process of trying to restore/recover from it. I'll let you know when we're up and running again.

Kind regards
Simon

#1770801

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Simon,

I'll put this ticket as waiting for your feedback until you replied that the server is available.

Looking forward to your reply.

#1771837

HI Jamal

We're back online.. 😅Our server was hit by a virus. The virus injected code into some of the files in our wp-content folder, including Toolset Blocks. For that reason I've tried to only re-install what I consider to be essential plugins. That means that File Manager is no longer installed. If you need FTP access, please let me know in a private reply and I can create an FTP account for you.

Thanks and best regards
Simon

#1772211

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I thought about this feature and our requirement to sync the favorite flag across duplicates or how we could use Toolset relationships and I am still not sure of any easy solution that wouldn't require custom code.

I analyzed the Favorite plugin a bit, and I was able to locate an action that is executed after updating the flag on a post. It is called "favorites_after_favorite" and it is located in "favorites\app\Listeners\FavoriteButton.php" at line 70. But is not useful if we are not able to programmatically favorite a post. The plugin does not offer such a function.

So, I thought about another solution. Instead of syncing the favorite status across languages, why not, setting this value only for the original post. The idea is to use a content template for each feature of the plugin. For example, if you want to display the favorite button, instead of using a shortcode directly, put the shortcode in a content template, and use that content template by passing to it the ID of the original post.
This will require, that we build a shortcode that will perform the following:
- Return the original post ID if the current post is a duplicate.
- Return the current post ID if it is original.

But this can bring some complexities to other features. For example, the list of favorite posts. I am not sure what will it return? The favorite post in the current language or across languages. Then we can loop through the results and return the duplicate or the current post based on the current language.

I am discussing your request with my team to get another opinion, I'll get back to you if we find any.

But, In the meantime, I believe that the best solution would be to hire a WPML contractor to build this feature for you. https://wpml.org/contractors/
Or to try other plugins that could offer this feature, check these lists:
- https://wordpress.org/plugins/tags/favorites/
- https://wordpress.org/plugins/tags/like/
- https://wordpress.org/plugins/tags/likes/

I have also come across this support request form for the plugin at the bottom of this page, maybe you can use it to contact the plugin's developer hidden link

#1778495

HI Jamal

I viewed all the links you sent me and, frustratingly, it would appear to me that all the suggested plugins would suffer from the same WPML flaw, that the originals and duplicates/translations would get out of sync if one favourited a duplicate/translated post rather than the original. Am I right in my thinking?

Did you get any more feedback from your colleagues? Can WPML create some code to allow this? I'm surely not the only customer facing this issue.

Thanks and kind regards
Simon

#1780033

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Simon,

I did get some feedback, but we have already discussed those. I think that we can come up with a solution using One-to-Many relationship, and a custom code that will duplicate the "Favorite" post and create the relationships to the parent's duplicate too.
We'll need to try it and test each workflow (favorite, unfavorite, my favorites, post's favorites, etc...)

Would you like to try that? I can create a test installation on our platform.

Please note, that the latest release of Toolset Types and WPML was released this week and has some major changes regarding relationships and how translation is performed. There is a relationship migration process that needs to be run after the update in Toolset->Relationships.

Let me know what you would prefer.

#1784881

Hi Jamal

I think it would be useful to get that nut cracked once and for all. I'd be willing to try it out.

Our site is up again. We got hit twice by some backdoor virus. Bloody nightmare! 🙁

It's funny you should mention there was a migration process that needed to be run afterwards regarding Relationships. When I go to Toolset > Relationships, I noticed that ours had all disappeared (we only had 2) however I can still see them on the database. So it looks like they're still there somehow. Is there some wizard or something we're supposed to run? Or some new setting somewhere? I had a look but couldn't find any.

Kind regards
Simon

#1785915

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Simon,

I reached our 2nd Tier and he explained that the wizard will only appear if you have more than 100 posts in relationships. If you have less than that, the migration will be done silently.

I visited your website and I can't see any relationships in Toolset->Relationships. I understood, that you already had 2 relationships and they are not displaying any more, right?
In that case, please update to the latest patched version and visit Toolset->Relationships again to check if you will get the wizard to run or your relationships back.

#1785959
Screenshot 2020-09-22 at 14.42.07.png

HI Jamal

I updated to all the latest versions of Toolset plugins. I still see the two relationships on the database (see screenshot) but these are not appearing in the Toolset > Relationships GUI.

I appreciate you guys want to keep issues separate - I don't wanna crowd this Favourites ticket with a separate issue, if you prefer you could split it into a separate ticket.

Kind regards
Simon

New threads created by Jamal and linked to this one are listed below:

https://toolset.com/forums/topic/relationships-dissappeard-after-the-last-update/

#1787575

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Thank you for your understanding and collaboration. I split a new ticket to handle this relationship issue.

If you would like to work on the favorites system without waiting for the relationship issue to be resolved, I can provide a test site on our platform. Let me know what you would prefer.

#1788901

Hi Jamal

I would prefer to get our Related Ads working again before proceeding with Favourites if you don't mind.

Kind regards
Simon

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.