Site logo

Archived topic

Query loop wp recipe maker

19 replies · Started by Kees on October 3, 2022

Viewing posts 16–20 of 20

Oke, thanks, i will ask that.

You're welcome Kees!

FYI, we made it work with https://help.bootstrapped.ventures/article/110-access-recipes-in-a-post-via-code

Now the code looks like this:

add_filter( 'render_block', function( $block_content, $block ) {
if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'insert-my-shortcode' ) !== false ) {

$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();
}

$block_content = do_shortcode('[wprm-recipe-time type="total" id="'.$recipe_id.'" ]');

}

return $block_content;
}, 10, 2 );

If the code can be optimized, let me know

I see. It does need an ID generated by the plugin. I thought it was using the Post ID which was why the code wasn't working in the first place.

It looks good. Thank you for sharing!

This archived topic is closed to new replies.