WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
[resolved] "wpcf-" on custom fields (13 posts)

  1. C W
    Member
    Posted 2 years ago #

    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.

    http://wordpress.org/extend/plugins/types/

  2. peter.grafico
    Member
    Posted 2 years ago #

    how can I remove the "wpcf-" and leave the name of the custom field the field slug that I've inserted?
    anyone knows?

  3. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  4. C W
    Member
    Posted 2 years ago #

    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?

  5. C W
    Member
    Posted 2 years ago #

    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.

  6. yivi
    Member
    Posted 1 year ago #

    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.-

  7. mommygeekology
    Member
    Posted 1 year ago #

    @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: http://wp-types.com/documentation/user-guides/displaying-wordpress-custom-fields/

  8. C W
    Member
    Posted 1 year ago #

    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.

  9. AmirHelzer
    Member
    Plugin Author

    Posted 1 year ago #

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

  10. a.blok
    Member
    Posted 1 year ago #

    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!

  11. a.blok
    Member
    Posted 1 year ago #

    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;
    }
  12. derekisbusy
    Member
    Posted 1 year ago #

    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.

  13. a.blok
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.