Site logo

Archived topic

Query loop wp recipe maker

19 replies · Started by Kees on October 3, 2022

Viewing posts 1–15 of 20

Hi Kees,

Have you tried using a block element - content template, and adding shortcode block with the shortcode from the plugin to the block element?

Let me know if that works.

Hi,

But it is just a part of the homepage, not the full homepage. With a block element you replaces the content.
Therefore we use the query loop.

Hi Kees,

We'll need to code it in. Shortcodes don't work in the WordPress or GenerateBlocks Query Loop Block. It's a WordPress issue.

Can you provide the link to your site, and we'll take a look at your Query loop? And, can you also point out where exactly in the loop would you like to add the Shortcode?

You may use the Private Information field for this: https://docs.generatepress.com/article/using-the-premium-support-forum/#private-information

Ideally, for a structure like that, you'll need to add the image to the Container Block, and then add the contents inside.

Now, for the Shortcode, add a GB Headline Block as a placeholder. Enable dynamic data and set the Source to anything, like Title.

Then add class insert-my-shortcode to the class list of the Headline Block.

How to add custom class: https://wordpress.com/support/adding-additional-css-classes-to-blocks/

Then, add this Snippet:

add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){
	if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'insert-my-shortcode' ) !== false ) {
		
	$content = do_shortcode('[wprm-recipe]');
	}
	return $content;
}, 10, 3);

Replace the Shortcode with your shortcode. Not sure if [wprm-recipe] will grab the recipe of the current post. Do you need the ID for that?

Hi,

We are almost there. It only shows the same time for al posts. I used [wprm-recipe-time type="total"]. This is to show the total time. But i is for al the post the same. And i changed one recipe with another time.

Is there a way to fix this?

Not sure how that Shortcode works. If you place that Shortcode in individual Posts, do the intended values show?

Hi,

Yes, then the time is shown. See link in private.

Hi,

No, it keeps showing the same time for all the posts. Weird. Do you have an other option?

.

Can you try this snippet instead?:

add_filter( 'render_block', function( $block_content, $block ) {
    if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'insert-my-shortcode' ) !== false ) {
		
		$block_content =  $block_content . do_shortcode('[wprm-recipe-time type="total"]');
		
    }

    return $block_content;
}, 10, 2 );

Hi,

Nope, still not working. I feel sorry for you :p
Any other options?

I see. I think it's because of the Shortcode. I tested both PHP codes I provided on Shortcodes functioning to retrieve Post meta and it's working as expected.

I won't know why it's not working as I have no access to the Shortcode.

It would be best to reach out to the support of that plugin for assistance at this point. Ask if it's possible to add and make that shortcode work on a Query Loop Block through render_block filter.

This archived topic is closed to new replies.