• Resolved C W (VYSO)

    (@cyril-washbrook)


    This plugin appends “wpcf-” to the start of every custom field. Fortunately, I saw this in about 30 seconds, but I can see that others quite understandably found it a puzzle.
    (1) It’s a pointless behaviour that only makes things harder for people using the plugin. What possible purpose could it serve? Isn’t this plugin meant to integrate seamlessly?
    (2) Nowhere in the documentation or in the plugin itself do the plugin authors state that to use the custom field in a theme file, you need to append “wpcf-” to it.

    If you were feeling your way around WordPress and you’d hidden WordPress’s built-in custom fields module (or set up a custom post type where this was hidden), you would have absolutely no way of knowing why get_post_meta() wasn’t returning anything for a particular custom field. You’d just assume that the plugin was faulty.

    https://www.ads-software.com/extend/plugins/types/

Viewing 12 replies - 1 through 12 (of 12 total)
  • how can I remove the “wpcf-” and leave the name of the custom field the field slug that I’ve inserted?
    anyone knows?

    Plugin Author Amir Helzer

    (@amirhelzer)

    All the custom fields that are created originally with Types will have this prefix. However, any existing custom fields that you put under Types control will have whatever name you created for them.

    You can create custom fields from the regular WordPress post editor.

    Then, go to Types->Settings and assign them under Types control.

    Thread Starter C W (VYSO)

    (@cyril-washbrook)

    That doesn’t answer either of the two points I raised above:
    (1) Why have this behaviour in the first place?
    (2) If it is necessary or beneficial to have this behaviour, why is this detail not listed in either the documentation or the plugin itself? Don’t you think it would be quite important to let users know of this fact?

    Thread Starter C W (VYSO)

    (@cyril-washbrook)

    It’s poor form to mark topics as “resolved” when they aren’t resolved. I’ve asked a couple of questions – see my previous posts – and they haven’t been answered.

    In the same line than the original poster:

    – Any quick tips on avoiding the “wpcf-” behaviour? It’s messing up with my fields, and the “create fields in wp and then assign them to type control” it’s a bit convoluted feels clumsy.

    I’m browsing the source code trying to find where to change it, but a pointer would be helpful.

    I like the plugin and I’m seriously considering buying views to help my users, but I need to “fix” this first.

    Thanks and regards.

    I.-

    @cyril

    1) It’s a best practice for plugins to prefix their custom fields, functions and other with a unique prefix to avoid plugin conflicts.
    2) It’s listed in the documentation in Appendix A on this page – the area that talks about using get_post_meta to access a Types field: https://wp-types.com/documentation/user-guides/displaying-wordpress-custom-fields/

    Thread Starter C W (VYSO)

    (@cyril-washbrook)

    Pretty sure that documentation didn’t exist when I wrote this post (the timestamps on the images indicate it was only created last month). I long ago moved onto a different plugin that works seamlessly, but thanks for the reply anyway.

    Plugin Author Amir Helzer

    (@amirhelzer)

    I think that this topic is resolved, as no change in Types is required.

    Well, after some research I found a way to remove the wpcf- prefix to all fields.
    This is useful i.e. if you use Types to create the custom fields, but you don’t want to have the wp_post_meta table (and your php code) cluttered with the wpcf- prefix.
    Just run this function whenever you want to remove the prefix from all fields:

    function make_types_variables_controlled() {
        global $wpdb;
        $q = "SELECT option_value FROM {$wpdb->prefix}options WHERE option_name='wpcf-fields'";
        $rr = mysql_query($q);
        $r = mysql_result($rr, 0);
        $u = unserialize($r);
        foreach (array_keys($u) as $key) {
    	$u[$key]['data']['controlled'] = 1;
        }
        $ret = serialize($ret);
        $q2 = "UPDATE {$wpdb->prefix}options SET option_value = '$ret' WHERE option_name='wpcf-fields'";
        $rr2 = mysql_query($q2);
        return $rr2;
    }

    I tried it and it seems to do the job.
    I don’t know if there are any downsides to this.
    Use it at your own risk and backup the database before trying to use it (if something goes wrong you might lose all of your Types fields).
    Cheers!

    Sorry, there was an error in the above code. Do not use it!
    This works:

    function make_types_variables_controlled() {
        global $wpdb;
        $q = "SELECT option_value FROM {$wpdb->prefix}options WHERE option_name='wpcf-fields'";
        $rr = mysql_query($q);
        $old_value = mysql_result($rr, 0);
        $u = unserialize($old_value);
        if (!$u) $u = array();
        foreach (array_keys($u) as $key) {
    	$u[$key]['data']['controlled'] = 1;
        }
        $new_value = serialize($u);
        $q2 = "UPDATE {$wpdb->prefix}options SET option_value = '$new_value' WHERE option_name='wpcf-fields'";
        $rr2 = mysql_query($q2);
        return $rr2;
    }

    I think that this topic is resolved, as no change in Types is required.

    I disagree… this plugin would’ve worked perfectly for my project if it weren’t for the prefix.

    I think that this topic is resolved, as no change in Types is required.

    I also disagree. I don’t see interoperability as a luxury feature.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Plugin: Types – Custom Fields and Custom Post Types Management] "wpcf-" on custom fields’ is closed to new replies.