• Yet another great plugin, nice job team OnTheGoSystems!
    I have figured out the Types Fields API, but I have two issues.

    1. it seems there is no way to grab ONLY the Field Name using types_render_field. If I know the field-slug, how do I render out only the Field Name?
    2. Since all of the Custom Fields are Grouped and assigned to post type(s), and not only does this group have a nice name but also a handy group_id, how dose one query info such as Group Name, field-slugs, field-type, field description, etc… by group_id?

    This info seems to be missing from the Fields API…
    Thanks for any assistance!

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Baden

    (@baden03)

    Hey Baden, I had the exact same question. I solved it by making wpcf_admin_fields_get_fields_by_group accessible to the front end by adding the following function to types/embedded/frontend.php:

    /**
     * Gets all fields in group_id
     *
     * @param type $group_id
     * @return type
     */
    function types_render_group($group_id) {
        require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
        global $post;
        return wpcf_admin_fields_get_fields_by_group($group_id);
    }

    To get a full array with all custom field data for a specific group_id just call:

    $existing_fields_arr = types_render_group(6);

    Until there is an official fix, this is an easy work-around. Hope it helps!

    Hello,

    Thanks for the tips, is it possible to catch the group dynamically ?

    Best regards,

    Fred

    Thread Starter Baden

    (@baden03)

    Just though I would post a little update. Add the following to types/embedded/frontend.php where it SHOULD be included in the plugin… or, since the folks at OnTheGoSystems seem to be occupied otherwise, put it in your functions.php file to keep it around incase of upgrade:

    function types_render_group($target_group) {
    	global $post;
    	require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
    	//by known group_id
        if(is_numeric($target_group)){
    		return wpcf_admin_fields_get_fields_by_group($target_group);
    	}
    	//by known slug
        else{
    		$groups = wpcf_admin_fields_get_groups();
    		foreach($groups AS $group){
    			if($group['slug'] == $target_group){
    				return wpcf_admin_fields_get_fields_by_group($group['id']);
    			}
    		}
    	}
    	//check yourself, dude
    	return false;
    }

    Now to get a full array of a specific group you can simply call by either group ID:

    $existing_fields_arr = types_render_group(6);

    or by group slug:

    $existing_fields_arr = types_render_group('robot-details');

    If the current post type only has one group, on can dump all the associated meta data by simply calling WP’s the_meta.

    Hope this helps!

    Plugin Author Amir Helzer

    (@amirhelzer)

    Sorry for joining here late. We’re a bit loaded with support and it’s given here:
    https://wp-types.com/forums/

    There’s a section for ‘Types community support’, which is free after a short registration.

    Can we move these discussions to our forum? It will be a lot easier for us to help you (and everyone else) there.

    Thread Starter Baden

    (@baden03)

    This is how the function is used to print out ALL custom field names & values for a specific group-slug:

    <?php
    	$existing_fields = types_render_group('robot-details');
    	foreach($existing_fields as $field){
    		echo types_render_field($field["slug"], array('output' => 'html', 'show_name' => 'true'));
    	}
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Types – Custom Fields and Custom Post Types Management] Custom Field Names and field-slugs’ is closed to new replies.