Access recipes in a post via code
The following code can be used to find recipes in the current post (when in the loop):
// Get the recipes inside the current post. $recipes = WPRM_Recipe_Manager::get_recipe_ids_from_post(); // Access the first recipe, if there is one. if ( isset( $recipes[0] ) ) { $recipe_id = $recipes[0]; $recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id ); // Output the recipe name. echo $recipe->name(); }
Not in the loop? Use the following code to specify the post ID to get the recipes from:
$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_post( $post_id );
Or get all recipes inside a piece of content:
$recipes = WPRM_Recipe_Manager::get_recipe_ids_from_content( $post_content );