View Full Version : Resolved Where I make mistake in this if function?

08-09-2009, 08:00 PM
I have problem with simple if function. I can't get it to work although I tried everything, and I really don't know what is problem.

$my_field_id = get_option('my_field_id');
$broj = 1;

function my_field_callback() { ?>
<input name="my_field_id" type="checkbox" value="1"
if ($my_field_id == $broj)
} ?>
<?php } ?>

So get_option is WordPress function (http://codex.wordpress.org/Function_Reference/get_option) and it gets value correctly. If I echo $my_field_id I get correct values, either 0 or 1. This if should check if value is one and in that case it should print that checkbox is checked and if it is 0, it should print.

Problem is that no matter what value is, "checked" is always printed. What I'm doing wrong?

Thanks in advance

08-09-2009, 08:02 PM
In here, add the parts in red:

function my_field_callback() {
global $my_field_id, $broj;

That will make the variables available inside the function (which they currently are not).

Hope this helps.

08-09-2009, 08:35 PM
Yeah, that was it, thank you a lot!