Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following code:

<?php $buycheck = get_post_meta($post->ID, 'buy-link', true); ?>

                <?php if ( $buycheck ) : ?>
                    <div class="section-title sidebar span5">
                        <h5>Get This Release</h5>
                    </div>

                <?php else : ?>

                    <div class="section-title sidebar span5">
                        <h5>More Releases</h5>
                    </div>

                <?php endif; ?>

Later in my code I want to be able to say that if buy-link does not exist - i.e. there is no data in that field - then do something, else do something different.

Not sure how to do this!

share|improve this question
Close-voted as off topic. This is a PHP/boolean logic question, not a WordPress question. – Chip Bennett Jul 31 '12 at 22:12
1  
Umm... isn't the code you posted exactly what you're asking for? I don't see the problem here!? – TheDeadMedic Jul 31 '12 at 23:11
You can use if ( $buycheck ) multiple times in the same context where the variable exists. But this is very basic PHP and rather off topic here. :) – toscho Aug 1 '12 at 1:42

closed as off topic by Chip Bennett, toscho Aug 1 '12 at 1:43

Questions on WordPress Answers are expected to relate to WordPress within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

I have used this:

    if (!$buycheck) {
        do something if $buycheck does not exist;
    } else {
        do something if $buycheck exists;
    }
share|improve this answer
Thanks @Butchpage, however this wasn't so clear to me. Could you elaborate? – Olly F Jul 31 '12 at 22:09

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