Home › Forums › General Issues › acf if query problem › Reply To: acf if query problem
There isn’t any way to tell what you’re trying to do, for example, I have no idea what you’re attempting to do here or why
if( $field['farben'] != 'Schwarz'): ?>
$field as returned by ACF has no index named “farben”
Nor do I understand why you are using get_field_object()
instead of get_field()
The only thing I can really do is tell you how I’d set this up.
First I would create a checkbox field. The choices for this field would look something like this
#FF0000 : Red
#00FF00 : Grean
#0000FF : Blue
I would set the return value of this field to “Both (Array)”
Then, in my template I would do this, I’m only adding what would be needed for using the values returned.
$colors = get_field('name_of_color_field_here');
if ($colors) {
foreach ($colors as $color) {
?><div style="background-color: <?php
echo $color['value']; ?> title=<?php
echo $color['label']; ?>></div><?php
}
}
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.