Correct. Try this:
<?php echo do_shortcode('[expand title="Mehr Erfahren" swaptitle="Weniger" targclass="collapse-container" id="impressum" rel="star-highlander" findme="auto" trigclass="mehr-erfahren-trigger" tag="div"] <div class="mehr-erfahren-text-container"><div class="mehr-erfahren-text">'. the_sub_field('bodytext', 'option') .'</div></div>[/expand]'); ?>
Thanks for your fast reply.
When I insert your code, the collapsing text is positioned about the trigger.
Here is a link to the website: https://krenn.design/collapse-o-matic
It is the part under “Überschrift”.
Not sure what mehr-erfahren-text-container and mehr-erfahren-text elements are for… try:
<?php echo do_shortcode('[expand title="Mehr Erfahren" swaptitle="Weniger" targclass="collapse-container" id="impressum" rel="star-highlander" findme="auto" trigclass="mehr-erfahren-trigger" tag="div"]'. the_sub_field('bodytext', 'option') .'[/expand]'); ?>
Regardless, it’s best to start off small and add things one by one so you know what is causing your issue.
I tried this but still the same result.
Still not seeing any content for the_sub_field('bodytext', 'option')
try replacing this with the following:
<?php
$sub_field = the_sub_field('bodytext', 'option');
var_dump('sub_field:', sub_field);
echo do_shortcode('[expand title="Mehr Erfahren" swaptitle="Weniger" targclass="collapse-container" id="impressum" rel="star-highlander" findme="auto" trigclass="mehr-erfahren-trigger" tag="div"]'. sub_field .'[/expand]');
?>
The content for
the_sub_field('bodytext', 'option')
is positioned above the trigger. I renamed it to “Bodytext”.
Unfortunateley the last code is not working.
Please change:
to:
$sub_field = the_sub_field('bodytext', 'option');
var_dump('sub_field:', $sub_field);
echo do_shortcode('[expand title="Mehr Erfahren" swaptitle="Weniger" targclass="collapse-container" id="impressum" rel="star-highlander" findme="auto" trigclass="mehr-erfahren-trigger" tag="div"]'. $sub_field .'[/expand]');
Unfortunateley not working neither.
Would it help to use Collapse-Pro-Matic or Collapse Commander?
Unfortunateley not working neither.
Not so fast… take a look:
string(10) "sub_field:" NULL
This is a direct dump to the screen of the $sub_field variable defined as:
$sub_field = the_sub_field('bodytext', 'option');
var_dump('sub_field:', $sub_field);
So the_sub_field('bodytext', 'option') is returning: NULL
First, you will want to verify that the_sub_field function is working as desired.
Upgrading to either Collapse-Pro-Matic or Collapse Commander will not magically fix this, but it will provide you a very high level of support that will get this issue resolved a bit quicker… but, not required.
Thanks for your reply.
I’m not sure if I understand correctly, you mean that
the_sub_field('bodytext', 'option')
is not returning anything?
But it is returning the Text “Bodytext” that is positioned above the trigger?
Ah so!
This means that the_sub_field('bodytext', 'option') is not ‘returning’ the value, but rather directly echoing it. Assuming this is the ACF the_sub_field function, then the documentation provides the answer:
This function will display a sub field value from a repeater field or flexible content field loop. This function is used within a have_rows() loop.
This function is the same as echo get_sub_field(‘name’);.
So the correct code should use get_sub_field as follows:
$sub_field = get_sub_field(‘bodytext’, ‘option’);
echo do_shortcode('[expand title="Mehr Erfahren" swaptitle="Weniger" targclass="collapse-container" id="impressum" rel="star-highlander" findme="auto" trigclass="mehr-erfahren-trigger" tag="div"]'. $sub_field .'[/expand]');
We are going to close this issue as it’s not related to our plugin.
That is working neither, but if this is an acf related problem then I understand that you can`t give me support on this problem.
Thank you!
right. you can test this by using the following:
$sub_field = 'The target content';
echo do_shortcode('[expand title="Mehr Erfahren" swaptitle="Weniger" targclass="collapse-container" id="impressum" rel="star-highlander" findme="auto" trigclass="mehr-erfahren-trigger" tag="div"]'. $sub_field .'[/expand]');
If that works, then you need to focus on how to properly use the get_sub_field function.
All the best.