Support

Account

Home Forums General Issues Check for a specific select sub-field value

Solved

Check for a specific select sub-field value

  • Hello,

    I have group field type named ‘property_banners’. Within the group, I have a select field named ‘status_1’, with the following choices:

    • for_sale : For Sale
    • sold : Sold
    • reserved : Reserved
    • under_offer : Under Offer
    • pending : Pending

    When a post has the value ‘sold’, I am trying to output a simple text message, however, I am having trouble getting anything to display. Below is the code I have at the moment:

    <?php if ( have_rows( 'property_banners' ) ) : ?>
        <?php while ( have_rows( 'property_banners' ) ) : the_row(); ?>
            <?php if (get_sub_field( 'status_1' ) == 'sold') {
          echo "This property is not for sale";
    } ?>
        <?php endwhile; ?>
    <?php endif; ?>

    Nothing is outputted, unfortunately. I tried referencing the ACF documentation regarding conditional output but can’t seem to get it working.

    Thanks in advance.

  • <?php if ( have_rows( 'property_banners' ) ) : ?>
        <?php while ( have_rows( 'property_banners' ) ) : the_row(); ?>
            <?php if (get_sub_field( 'status_1' ) == 'Sold') {
          echo "Hi";
    } ?>
        <?php endwhile; ?>
    <?php endif; ?>

    Works. sold needed to be Sold

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.