Skip Navigation

[Resolved] Using a taxonomy to select ingredients and a field to write/select amount

This support ticket is created 4 years, 10 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Lykke Scavenius 4 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1450257

I want to know if it's possible to make it easier for the frontend creation of recipes to add a reciepe without creating multiple spellings of avocado in the database. If they had a dropdown field to select an ingredient, and add new in case it doesn't exist, and then a different field to select or write amount for this specifik recipe. I can't visualize how this could be done.

Thanks and regards
Lykke

#1450887

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Lykke

What are these ingredients? Custom fields or taxonomies?

Because if taxonomies then the interface for adding tags (or tag-like non-hierarchical taxonomies) is similar to what you suggest, as you start typing you will get auto-suggestions for existing tags which match what you type, but it still allows you to add new tags.

However, that's not really amenable to specifying a quantity.

For that you would probably need to use repeatable field groups, where the group contained a field for the ingredient and another for the quantity, so that they were linked together.

But there's no way to have the kind of user experience you describe that is somewhat like tags whereby users can choose from existing values or enter new ones.

You could try using an autocomplete library, but this isn't a feature of Toolset, you would need to code it yourself or find a developer to do it for you.

For example, take a look at hidden link

If you had a form to add repeatable field groups you could pass an array of existing field values to the front end (you would need custom PHP that used the WordPress function wp_localize_script for this), and use that array as the source for the autocomplete library.

See the official documentation (https://developer.wordpress.org/reference/functions/wp_localize_script/) or try this tutorial (hidden link) for more information about wp_localize_script.

#1452349

Hi Nigel,

Thanks for your reply. What you say makes sense. I want to find an acceptable solution, my client doesn't have the budget for custom development.

Have in mind I'm "used to" both Toolset and Gravity forms so I can easily get the features mixed up.

Yes "ingredients" would be a taxonomy for the post type "recipes". I have to also attach to every recipe which wine goes with the dish(if lunch or dinner) and how spicy it is, but I think these are just custom fields.

What came to me when you said repeatable group, is it possible that this group has a (searchable)dropdown field that contains all items from a taxonomy (ingredients) and a field for amount.
Then okay - they would have to use a different form or section to create new taxonomy items.
Possible/not possible?

I'm hoping to do this in Toolset only.

Thanks and regards
Lykke

#1456251

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The repeatable group is a container to group custom fields together, it is separate from taxonomies, you can't mix and match the two.

A taxonomy term can be assigned to multiple posts (as a way of showing they are related, e.g. of the same category) which means the terms are not unique for each post.

Even if you contrived connecting an ingredient taxonomy term (e.g. flour) to a quantity custom field (e.g. 400g), that would apply to all recipe posts that the ingredient was assigned to, which is clearly not what you want.

I don't see how it can work using a taxonomy for the ingredients, it needs to be a custom field (because that is unique to a post), but then you lose the UI to auto-suggest assigning existing values with the option of adding new ones.

If implementing that (as descrubed previously) is not an option then you could try looking at commercial recipe-type themes, it could be that one has such functionality built-in.

#1466925

I will create the ingredient lists as a repeating custom field. That'll be alright. I just had to make sure I couldn't do better. Thank you!
Lykke