0

I'm trying to work this query - the first if clause works, and the else works, but the middle clause, elseif, doesn't work.

<?php if(get_post_meta($post->ID, 'TourURL', true)) {
            <div class="tourenquiryonline">
            <h2>Book or Inquire</h2>
            This tour can be booked online.
            </div>

} elseif (get_post_meta($post->ID, 'bhid', true)){
            echo
                        <div class="tourenquiryonline">
            <h2>Book</h2>
            This tour can be booked online via the form on the right hand side of this page.
                        </div>
} else {
            <div class="tourenquiry">
                        <div id="wufoo-q7x2x3">
                        Fill out my <a href="http://touristisrael.wufoo.com/forms/q7x2x3">online form</a>.
            </div>
}?>
2
  • Your PHP is badly broken. You should be getting fatal parse errors.
    – s_ha_dum
    Commented Dec 22, 2013 at 18:26
  • The only difference I see in the 3 is an echo in the else if...does it work if you take that out? Commented Dec 22, 2013 at 19:52

2 Answers 2

1

This cannot work. It has to look like the following (or similar):

<?php
if (get_post_meta($post->ID, 'TourURL', true)) {
    ?>
    <div class="tourenquiryonline">
        <h2>Book or Inquire</h2>
        This tour can be booked online.
    </div>
    <?php
} elseif (get_post_meta($post->ID, 'bhid', true)) {
    ?>
    <div class="tourenquiryonline">
        <h2>Book</h2>
        This tour can be booked online via the form on the right hand side of this page.
    </div>
    <?php
} else {
    ?>
    <div class="tourenquiry">
        <div id="wufoo-q7x2x3">
        Fill out my <a href="http://touristisrael.wufoo.com/forms/q7x2x3">online form</a>.
        </div>
    <?php
}
?>

// Edit
And as you can see, you are missing a closing </div> in the else case.

4
  • Thanks. But this still doesn't work... I don't get errors, but the elesif still doesn't produce results Commented Dec 22, 2013 at 19:38
  • Well, then that's because either the 'bhid' post meta is false, or it is true but the 'TourURL' post meta is true as well - which won't let you enter the elseif.
    – tfrommen
    Commented Dec 22, 2013 at 20:22
  • bhid is true and working because it is populating a field in the sidebar, but this is to show or hide a piece of content in the main body... TourURL' is definitely false... Commented Dec 22, 2013 at 20:45
  • Well, then please do me a favor, and dump the data in question, compare the data with the current setup (i.e., the if ... elseif ... else ... block), and then figure out what you have to do to make it work like you want it to. How do you do this? Like so: echo 'TourURL: '; var_dump(get_post_meta($post->ID, 'TourURL', true)); echo "\n".'bhid: '; var_dump(get_post_meta($post->ID, 'bhid', true));. Put this right before the if. I'm pretty sure this will explain to you, why this still doesn't work.
    – tfrommen
    Commented Dec 22, 2013 at 22:18
-1

what´s about switch case with php?

switch ($i) {
case 0:
    echo "i equals 0";
    break;
case 1:
    echo "i equals 1";
    break;
case 2:
    echo "i equals 2";
    break;

}

1
  • i equals 2 can be replaced with if a value is present..? Commented Dec 22, 2013 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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