Hi,
I am using Conditional statement (Checkbox rvalue is an array) function to get two outputs. But if “None” checkbox is ticket I get this error:
“Warning: in_array() expects parameter 2 to be array, string given in…”
How can I do an “if empty” check or otherwise write it properly?
This is my code:
<?php if( in_array( 'Materialet er tilgængeligt til download', get_field('materiale') ) ) {echo '<a href="' . get_field('download') . '" target="_blank" class="readmore">Download PDF →</a>';}?>
<?php if( in_array( 'Materialet er tilgængeligt som eksternt link', get_field('materiale') ) ) {echo '<a href="' . get_field('link') . '" target="_blank" class="readmore" >Eksternt link →</a>';}?>
Thanks
Hi @Cheyens
I would first test the value of your get_field to see why the error is showing in the first place.
<?php
echo '<pre>';
var_dump(get_field('materiale'));
echo '</pre>';
die;
?>
What do you get?
Looks like there is no value saved for the field.
This means your in_array function will fail due to the wrong variable type.
Perhaps you need to also compare the value like so:
<?php
if( get_field('materiale') )
{
if( in_array( 'Materialet er tilgængeligt til download', get_field('materiale') ) )
{
echo '<a href="' . get_field('download') . '" target="_blank" class="readmore">Download PDF →</a>';
}
}
?>
Hi,
Thanks! That solved my problem 🙂