- This topic has 19 replies, 3 voices, and was last updated 2 years, 3 months ago by Fernando.
-
AuthorPosts
-
October 3, 2022 at 7:59 am #2361649Kees
Hi,
We would like to build a queryloop with data from blog posts and WP recipemaker data.
Wp recipemaker has shortcodes.How can we use the shortcodes in a recipe?
https://help.bootstrapped.ventures/article/83-recipe-shortcodes
October 3, 2022 at 1:12 pm #2361948YingStaffCustomer SupportHi 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.
October 3, 2022 at 11:44 pm #2362274KeesHi,
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.October 3, 2022 at 11:51 pm #2362281Fernando Customer SupportHi 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
October 4, 2022 at 1:00 am #2362345KeesHi,
Nice. I made a fresh installation for you.
See login in private information. See the wp recipe maker data: https://help.bootstrapped.ventures/article/83-recipe-shortcodesIt is important the the data is shown. The styling is the part we can fix.
October 4, 2022 at 1:28 am #2362380Fernando Customer SupportIdeally, 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?October 4, 2022 at 3:19 am #2362468KeesHi,
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?
October 4, 2022 at 5:21 pm #2363403Fernando Customer SupportNot sure how that Shortcode works. If you place that Shortcode in individual Posts, do the intended values show?
October 5, 2022 at 1:03 am #2363722KeesHi,
Yes, then the time is shown. See link in private.
October 5, 2022 at 1:21 am #2363749Fernando Customer SupportI changed the code above: https://generatepress.com/forums/topic/query-loop-wp-recipe-maker/#post-2362380
Can you use that instead? And remove
class
from the class list of the Headline Block.October 5, 2022 at 1:26 am #2363756KeesHi,
No, it keeps showing the same time for all the posts. Weird. Do you have an other option?
October 5, 2022 at 1:28 am #2363761Kees.
October 5, 2022 at 1:30 am #2363764Fernando Customer SupportCan 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 );
October 5, 2022 at 1:32 am #2363766KeesHi,
Nope, still not working. I feel sorry for you :p
Any other options?October 5, 2022 at 1:36 am #2363770Fernando Customer SupportI 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. -
AuthorPosts
- You must be logged in to reply to this topic.