Home Forums General Issues get_field / get_sub_field conditional? Reply To: get_field / get_sub_field conditional?

  • An old post, back to life!

    My solution for this is a function.

    function get_acf_field( $name, $id = null ) {
        $field = get_sub_field( $name, $id ) ? get_sub_field( $name, $id ) : get_field( $name, $id );
        return $field;

    Seems to work for my needs. Hopefully it’ll help others. This gives me the ability to use the same component within a repeater/flex content or standalone on a page/post. @hube2 Your idea would also be a good solution so that the component fields are always a sub field. That makes sense too. Probably a bit faster too than doing the conditional check for every field.