Support » Plugin: Cooked - Recipe Plugin » How do I find the Nutrition Facts by usin the API call URL

  • Resolved lgallus

    (@lgallus)


    Hello,

    actually I’m using this URL to show the recipe with ID 701 in my iOS app.

    Now I also need the nutrition facts but I don’t know how to find them by using a specific URL. Does someone has an idea how to find this data by using an URL?

    Im a beginner at this topic so please be patient with me 🙂

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Boxy Studio

    (@boxystudio)

    @lgallus:

    There is no REST API url to grab the nutrition facts right now, but this is a great idea. Thanks for the feedback!

    Jorge Rodriguez

    (@catupiryisjustcreamcheese)

    I would like to just say something here. I also have interest in this kind of development if possible. The USDA Food Composition Databases offer a free API to request this kind of information.

    https://ndb.nal.usda.gov/doc/

    Awesome plugin this one. I really like it.

    Cheers

    Johnathan Miller

    (@johnathan-miller)

    @lgallus @boxystudio Here is what I’m doing to pull in recipe meta data.

    Place this in your functions.php file

    
    if (class_exists('Cooked_Plugin')) {
        add_action('rest_api_init', 'api_posts_meta_field');
        function api_posts_meta_field() {
            register_rest_field('cp_recipe', '_meta', array(
                'get_callback' => 'rest_get_post_meta',
                'schema' => null
            ));
        }
    
        function rest_get_post_meta($object) {
            $post_id = $object['id'];
            $post_meta = get_post_meta($post_id);
            $recipe_meta = array();
    
            if (isset($post_meta['_recipe_settings'])) {
                $post_meta_unserialized = unserialize($post_meta['_recipe_settings'][0]);
    
                foreach ($post_meta_unserialized as $k => $v) {
                    if (in_array($k, array('difficulty_level', 'prep_time', 'cook_time', 'total_time', 'ingredients', 'directions', 'nutrition', 'gallery'))) {
                        $recipe_meta[$k] = $v;
                    }
                }
            }
    
            return $recipe_meta;
        }
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I find the Nutrition Facts by usin the API call URL’ is closed to new replies.