Trying the above code is causing a warning error to be thrown with my usage and I don’t understand why.
Warning: Invalid argument supplied for foreach()
<?php
$portfolioContent = get_field('portfolio_content'); // this is the group field
if ($portfolioContent) :
$skills = $portfolioContent['skills'];
$field = get_field_object($skills);
?>
<h1><?php echo $subTitle; ?></h1>
<?php
if ($skills) : ?>
<ul>
<?php foreach ($field['choices'] as $v => $l) : ?>
<li><?php echo $l; ?></li>
<?php endforeach; ?>
</ul>
<?php endif;
?>
<?php endif;
?>
$skills = the checkboxes
print_r($skills);
// return value = value
Array ( [0] => wordPress [1] => javascript [2] => jquery [3] => scss [4] => responsive-design [5] => photoshop [6] => illustrator )
// return value = both
Array ( [0] => Array ( [value] => wordPress [label] => WordPress ) [1] => Array ( [value] => javascript [label] => Javascript ) [2] => Array ( [value] => jquery [label] => jQuery ) [3] => Array ( [value] => scss [label] => SCSS ) [4] => Array ( [value] => responsive-design [label] => Responsive Design ) [5] => Array ( [value] => photoshop [label] => Photoshop ) [6] => Array ( [value] => illustrator [label] => Illustrator ) )
Thank you. Can you tell me why it’s necessary to use _ instead of – here or point me in the right direction to learn more?
I’m using Contact 7 forms in this way. I have a flexible content field I’m using as a page builder.
I added my shortcode to a text field schedule_a_demo_form
like this;
[contact-form-7 id="xxx" title="Schedule A Demo"]
In my template I do this;
$scheduleADemoForm = get_sub_field('schedule_a_demo_form');
echo do_shortcode($scheduleADemoForm);
Also, to prevent users from altering the shortcode in the text field I added a class admin-readonly
to the wrapper and in my admin-styles.css
added this style;
.admin-readonly {
pointer-events: none;
}
This prevents them from accessing the input (unless they know how to use developer tools that is 🙂 )
Got it! This just happens to be a nested flexible content field.
<?php if (get_row_layout() == 'flexibl_content_field') :
$layouts = get_sub_field('sub_flexible_content_field');
$layoutsCount = count($layouts);
?>
and use it like this in the while loop
<div class="col-md-6 <?php echo $layoutsCount == 3 ? 'col-lg-4' : 'col-lg-6'; ?>
Thanks for the thorough examples @hube2! The get sections as an array code works perfectly for my needs.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.