Home Forums General Issues Check Field Type


Check Field Type

  • I want to be able to check a field type

    I was thinking like this:

    $field = get_field_object( $fieldkey, $fieldgroup_id);
    $name = $field[‘name’]; $type = $field[‘type’];
    $type = [‘true_false’]

    Then use if statement for if true_false was true? But this doesn’t work. $type = [‘true_false’] just seems to check if the field has a type, not which type of type.

    I have had a look at the filter section but I don’t think it is appropriate here? Any help greatly appreciated.

  • I use this:

    <?php if (get_field(‘field_name’) != ”) { ?>
    <?php echo the_field(‘field_name’); ?>
    <?php } else { ?>
    If not filled. Then put code here.
    <?php } ?>

  • Thanks owenoneill, but I only want to get fields that are true_false types. Your code seems to be getting the field name? Apologies if my initial question wasn’t clear.

  • Hi @webpod

    The code:

    $type = ['true_false'] 

    Does not check anything.

    To compare the type, you would do this:

    if( $field['type'] == 'true_false' )
        // do something
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Check Field Type’ is closed to new replies.