Home Forums General Issues Check Field Type


Check Field Type

    • webpod

    • October 28, 2013 at 10:58 pm

    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 } ?>

    • webpod

    • October 28, 2013 at 11:33 pm

    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.

    • Elliot

    • October 29, 2013 at 5:50 pm

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.