- This topic has 5 replies, 2 voices, and was last updated 5 years, 1 month ago by
David.
-
AuthorPosts
-
February 12, 2021 at 4:17 am #1655581
Timo de Vries
Hi,
I am trying to populate a shortcode with a custom field. I tried using the hook element, activated “Execute Shortcodes” and “Execute PHP” and added: [CP_CALCULATED_FIELDS id=”<?php the_field(‘testid’); ?>”]
but had no luck. Can you help me figuring out on how to achieve that?At the same time the shortcode should be inserted in one of my containers. This seems to not be possible with hooks, any solutions on that?
All in all I have the same layout for all of my posts. I would like to create that layout with the “Blocks” Element, fill it with some styles and containers and add a shortcode ([CP_CALCULATED_FIELDS id=”XXX”] where the XXX should be populated with a custom field (no matter if I use ACF or default post meta fields).
Thanks
February 12, 2021 at 7:23 am #1655952David
StaffCustomer SupportHi there,
where does the shortcode come from ? Did you create it or is it from another plugin ?
February 12, 2021 at 7:25 am #1655959Timo de Vries
It‘s from a plugin (https://de.wordpress.org/plugins/calculated-fields-form/).
February 12, 2021 at 9:00 am #1656086David
StaffCustomer SupportFor the hook element you could something like this for example:
$itemid = get_field( "item_id" ); $shortcode = '[the_shortcode id="'.$itemid.'"]'; echo do_shortcode($shortcode);For the Block Element its a bit trickier as your sort of asking for a shortcode within a shortcode as Blocks won’t accept PHP.
I would suggest asking the developer if they have a PHP function for calling the content instead of a shortcode.
Then you could create your own shortcode to output that function.
February 12, 2021 at 10:37 am #1656187Timo de Vries
Hi David,
thanks for the snipppet!
I contacted the developer and there doesn’t seem a function for calling the content of the shortcode.As my block layout is pretty basic, I might just use it in the hook. The plain HTML looks like that:
<section class="gb-container gb-container-db2ef2d5 alignwide"> <div class="gb-inside-container"> <div class="gb-container gb-container-7b4c3815"> <div class="gb-inside-container"> SHORTCODE OUTPUT </div> </div> </div> </section>I assume the gb-container-ID is used to apply the custom styles. Can I just omit the individual ID and assign my own class like
<div class="gb-container gb-container-testclass">
or do I need it for anything?February 12, 2021 at 2:25 pm #1656380David
StaffCustomer SupportAre you wanting to use styles from a GB Block ?
-
AuthorPosts
- You must be logged in to reply to this topic.