Karsten Thiemann
Karsten Thiemann

Reputation: 61

background colors with CSS3? ACF / advancedcustomfields

i used ACF's. I have a checkbox with Colors like:

1C00ff00 : Transparent 000000 : Black 3072B5 : Blue etc....

i embed this code in my template to change the text an icon

    <?php
$field = get_field_object('farben');
$colors = $field['value'];
if( $colors ): ?>
    <?php foreach( $colors as $color ): ?>
        <div style="float: left; width: 10px; height: 10px; margin-right: 3px; border: 1px solid #000000; background-color:<?php echo $color; ?>"></div>
    <?php endforeach; ?>
<?php endif; ?>

now i want to use an icon for "multicolor"....

Can anyone help me? This Code doesnt change the icon:

<?php 
  $field = get_field_object('farben');
 ?>
         <div style="float: left; width: 10px; height: 10px; margin-right: 3px; border: 1px solid #000000; background-image: url('/media/multicolor.png') <?php if ($field == multicolor) { echo 'multicolor';}?>"></div>

Upvotes: 1

Views: 127

Answers (1)

Jarom
Jarom

Reputation: 561

From the documentation on https://www.advancedcustomfields.com/resources/get_field_object/

get_field_object

This function will return an array looking something like the following. Please note that each field contains unique settings.

array(
  'ID'                => 0,
  'key'               => '',
  'label'             => '',
  'name'              => '',
  'prefix'            => '',
  'type'              => 'text',
  'value'             => null,
  'menu_order'        => 0,
  'instructions'      => '',
  'required'          => 0,
  'id'                => '',
  'class'             => '',
  'conditional_logic' => 0,
  'parent'            => 0,
  'wrapper'           => array(
    'width'             => '',
    'class'             => '',
    'id'                => ''
  )
);

Thus, you are probably looking for an array value. Try printing out $field = get_field_object('farben'); from your second example, like so:

 echo '<pre>'.print_r($field,1).'</pre>';//the value you are looking for is in here, probably.  

Don't echo $field; but instead you should echo $field['value']; or something similar. Printing the array will help you see what you are missing.

Upvotes: 1

Related Questions