• Types and its related suite of plugins provide a very comprehensive and robust set of tools that allows a user to “avoid” programming.

    However, for our project, we can across a fatal deal-breaker: When custom fields are created by Types, the names start with a prefix of “wpcf-” and then the remainder of the field name uses hyphens instead of underscores. Nor, does Types allow us to edit the names of the custom fields once they are created.

    For example, one of our custom field names was “wpcf-shortcode-name” instead of “wpcf_shortcode_name”.

    Why does this matter? If you stay completely within the Types environment and avoid all programming, it does not – Then, 5 stars.

    However, for our website we have a 500+ line PHP function that we use. And, PHP does not allow hyphens to be used in a variable name – such as the name of a custom field. Thus, I cannot programatically access any of the custom fields created by Types.

    I suppose that I could use some type of CamelCase, but then I still have the “wpcf-” prefix to deal with. Our research indicates that there is a “hack” that allows the end-user to modify or even eliminate the prefix. But, I shouldn’t need to hack it in the first place.

    I consider this to be a serious oversight by the Types developers. I hope they will correct this issue in the future. Until then, 1 star.

    Thank-you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m not sure exactly how you’re finding the variables. But I’ve found, in order to access a variable the plugin stores for you, you simply do as follows:

    // $post comes from "The Loop" in my case
    $post_meta = get_post_meta($post->ID);
    
    $custom_field_array_value = $post_meta['wpcf-variable-name'];
    $custom_field_single_value = $post_meta['wpcf-variable-name'][0];

    Hope that gives you ideas on how to work around this “issue.” Hate to see such an amazing plugin receive bad ratings!

    Barry

    (@barryhughes-1)

    And, PHP does not allow hyphens to be used in a variable name

    Hate to be a pedant, but that’s not actually true. This sort of thing is valid:

    $someObject->{'var-name-with-hyphens'};

    Anonymous User 14808221

    (@anonymized-14808221)

    Hello @reecejr.

    I apologize for the late reply.

    Please let me explain.

    You can not use hyphens in a “normal” variable, yes this is partially true.
    But, you can not anyway access the field with a variable only.

    WordPress, Types API and PHP will reuqire you to assign a value to a $varaiable_name.
    And that is done with get_post_meta() or types_render_field()

    There is no reason to have underscores in a Custom Field So Far.

    YOu can not access a value of a Field by simply saying $this_is_my_field_meta_key.
    It won’t happen anything if you do that.

    I might miss a crucial Point here, but I do not understand why the Plugin is bad due to this (non breaking) property.

    Please let us know why this was a breaking issue for you.

    We are always ready to improve.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Internal variables use hyphens instead of underscores.’ is closed to new replies.