I've trying to run a conditional on the custom field I made with the Custom Fields plugin, I made a true and false check box.

I just need to check if the box is true or false really. I've tried something like this but the word hello appears even when the

    $premium = get_field('premium');
    if ( !isset($premium)) {
        echo 'hello';

Basically I've trying to change the page layout if this is ticked. I'm sure this is quite easy.

Thanks for any input


This can't work because isset() returns true if there is a value, trueand false are values, ergo it won't work. Do it like this instead:

$premium = get_field('premium');
if ( ! $premium ) { // this is basically short for $premium == false
    echo 'not premium';
|improve this answer|||||
  • Aww thanks Ialocin again!, I was at the understanding ! had to have either empty or isset with it. This should work for what I'm wanting now then. Least I'm getting slightly closer to the awnser each time haha!. – dannyw24 Dec 6 '13 at 9:52
  • It really seems like I'm always there, when you're asking your questions. BTW for getting such things straight it's always good to know your PHP Manual. @dannyw24 – Nicolai Dec 6 '13 at 10:06
  • I've just ran this on my site Ialocin, Tried ticking the box and unticking it always outputs not premium. If I'm correct when its not ticked it should output 'not premium' - Believe I had the field name wrong therefore it was always false. Just changed this now to ('premium_stock_supplier') – dannyw24 Dec 6 '13 at 10:12
  • Have you debugged what the actual values in your field are? @dannyw24 – Nicolai Dec 6 '13 at 10:14
  • Marked this correct now @ialocin. Thanks again for the help. – dannyw24 Dec 6 '13 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.