If Then Question

Support General If Then QuestionResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27630
    Rebecca RobertsonRebecca Robertson
    Participant

    I want to change how a field is displayed on the frontend depending on the rwmb_meta(), kind of like this:

    <?php if( rwmb_meta() = '1' ) { ?>
    ...
    <?php } elseif( rwmb_meta() = '2' ) { ?>
    ...
    <?php } elseif( rwmb_meta() = '3' ) { ?>
    ...
    <?php } else { ?>
    ...
    <?php } ?>
    

    where the number after = is whatever the value of rwmb_meta() is.

    I know how to do this with general WP elements such as category or page, but how would I do it for Meta Box fields?

    #27645
    Long NguyenLong Nguyen
    Moderator

    Hi Rebecca,

    To compare two values, please use the equal comparison operator ==

    <?php if( rwmb_meta('field_id') == '1' ) { ?>

    Get more details here https://www.php.net/manual/en/language.operators.comparison.php

    #27707
    Rebecca RobertsonRebecca Robertson
    Participant

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.