Custom Fields
Support General Recipe: Ingredients * calculate portions

  • Creator
  • #29423
    Resolved Tobias Haas

    I am currently building a page for myself to learn.
    A recipe page where I can save my favorite recipes.

    Everything works so far. I have a "Custom Post Type" called a recipe. And some "Custom Fields" like cooking time, ingredients, portions and cooking instructions

    I would now like to have the number of ingredients calculated
    Ingredients * servings

    Are there already instructions for this or does someone have tips?

    Many Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
  • #29434
    Long Nguyen

    Hi Tobias,

    If you follow this article to create a Recipe with Meta Box and want to show the number of ingredients calculated, I recommend using the field number for ingredients instead of WYSIWYG. Then you can calculate the ingredient as well

    $ingredient = rwmb_meta( 'ingredient' );
    $calc_ingredient = $ingredient * 123;

    Or follow this topic

    Tobias Haas

    Hey Long, thank you very much for your answer.
    But what do I do if I want to name my ingredients and specify the number of tomatoes, for example, that are calculated at the same time as the servings?

    1x tomato * number of servings

    If I define the field as a Number, I can no longer enter the name of the ingredient.

    Long Nguyen


    Get the number of a specific ingredient in the WYSIWYG is not possible. You can try to use two fields, one number, and one text field in a group and make it cloneable to add more ingredients.

    Tobias Haas

    Hey Long,
    I have now created a group

    • Label: ingredient_group
    • ID: ingredient_group
    • Type: Group
    • Cloneable: yes

    In this group I have added 4 fields.

    • Label: Number of ingredients
    • ID: number_ingredients
    • Type: number
    • Label: Unit of measure
    • ID: unit
    • Type: Select Advanced
    • Choises: l, ml, g, kg...
    • Label: ingredient
    • ID: ingredient
    • Type: Text
    • Label: calculation
    • ID: calculation
    • Type: number
    • Read only: yes

    Outside of the Group i have another Custom Field

    • Label: portions
    • ID: portions
    • Type: Number

    Im using the Oxygen Builder, so i added this Snippet to the Plugin "Code Snippets"

    add_action ( '', function() {
       <script type="text/javascript">
          jQuery(document).ready(function($) {
             $('body').on('keyup', '#portions, #number_ingredients', function() {
                var portions = $('#portions').val();
                var number_ingredients = $('#number_ingredients').val();
                var calculation = portions * number_ingredients;

    Unfortunately it does not work... What am I doing wrong?

    Kind Regards and thanks for your Help!

    Long Nguyen

    Hi Tobias,

    Use JavaScript code to get the subfield value in a group to calculate is very complicated. The subfield in a group will have an ID like groupID_subfieldID, does not the same as the sample code above. This screen record is an example

    Then you will need to create more code if the group field is cloneable. You can contact us here to create a service request for this case. I will assign it to the developer team, they will estimate the job and get back to you with a quote.

    Tobias Haas

    Hey Long, thank you very much!
    Good to now! 😉

    I created a Service Request.


Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.