Support » Plugin: WP Recipe Maker » Get Recipe data in custom rest api

  • Resolved moorthyit

    (@moorthyit)


    Hi,

    Thank for great plugin. We are trying to add our recipes data in our custom rest api. Can you please tell us how we can get recipes data from post id?

    Thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Brecht

    (@brechtvds)

    You could get the recipe IDs from the post content using this function:

    $recipe_ids = WPRM_Recipe_Manager::get_recipe_ids_from_content( $post_content );

    The recipe data is already available through the WordPress REST API as well: https://bootstrapped.ventures/wp-recipe-maker/wordpress-rest-api/

    Kind regards,
    Brecht

    Thread Starter moorthyit

    (@moorthyit)

    Hi,

    Thank you for your reply. Actually we are building custom API with custom structured data for our external application.
    We have tried the below code but it returns false

    $content = get_post_field( 'post_content', $post_id );
    $recipe_ids = WPRM_Recipe_Manager::get_recipe_ids_from_content( $content ); //it returns a single recipe id
    $recipe = WPRM_Recipe_Manager::get_recipe( $recipe_ids); 

    We got $recipe as ‘false’. Can you please tell us what might be issue?

    Plugin Author Brecht

    (@brechtvds)

    $recipe_ids will be an array. You need to pass an int to the get_recipe function. So something like:

    $recipe = WPRM_Recipe_Manager::get_recipe( $recipe_ids[0] );

    But you’ll want to add some checks in there to make sure $recipe_ids has at least 1 recipe.

    Brecht

    Thread Starter moorthyit

    (@moorthyit)

    Hi,

    Thank you for reply. I have added as per your instructions but it return empty array

    $content = get_post_field( 'post_content', $post_id );
    $recipe_ids = WPRM_Recipe_Manager::get_recipe_ids_from_content( $content );
    $recipe = WPRM_Recipe_Manager::get_recipe($recipe_ids[0]);

    Output:

    “recipe_ids”: [
    36173
    ],
    “recipe”: {}

    Can you please tell us what might be the issue? Thanks

    Plugin Author Brecht

    (@brechtvds)

    Hard to say what the problem is like this. Is 36173 an actual recipe?

    Brecht

    Thread Starter moorthyit

    (@moorthyit)

    Hi,

    Thank you for your wonderful support. I figured out it and now I am getting the recipes values with that $recipe object by

    $content = get_post_field( 'post_content', $post_id );
    $recipe_ids = WPRM_Recipe_Manager::get_recipe_ids_from_content( $content );
    $recipe = WPRM_Recipe_Manager::get_recipe($recipe_ids[0]);
    $recipe_name= $recipe->name();
    $recipe_name= $recipe->summary();

    Once again, Thank you for the great plugin and your support. I am really appreciate it.
    Thanks.

    Thread Starter moorthyit

    (@moorthyit)

    Hi,

    We got all recipe data except ‘course’ and ‘cuisine’. Can you please tell us how can we get those information from recipe id?. Thanks in advance.

    Plugin Author Brecht

    (@brechtvds)

    The easiest way to get everything is to use $recipe->get_data();
    Otherwise $recipe->tags( ‘course’ ); and $recipe->tags( ‘cuisine’ ); should work as well.

    Thread Starter moorthyit

    (@moorthyit)

    Hi,

    We got those values too by calling ‘tags()’ function.

    $courses = $recipe->tags( 'course' );

    Thanks

    Thread Starter moorthyit

    (@moorthyit)

    yes, Thank you for your great support.

    Thread Starter moorthyit

    (@moorthyit)

    Hi,

    Is it possible to get recipes list sorted by average rating value in REST API?. Thanks in advance.

    Plugin Author Brecht

    (@brechtvds)

    I’m actually not sure if it’s possible to sort by meta key in the WordPress REST API. If it is, then you can sort by the wprm_rating_average meta value.

    Brecht

    Thread Starter moorthyit

    (@moorthyit)

    Ok. Thank you for your reply.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Get Recipe data in custom rest api’ is closed to new replies.