Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jared Cobb

    (@jaredcobb)

    Hi Jeremy,

    Yes, you’re able to customize the “post mapping”. The post mapping is simply a config that tells WordPress “This XML node goes to that post field”. The plugin has a filter that you can hook into in your theme or your own plugin like so:

    /**
     * Customize the post mappings from the CCB API XML nodes
     * to the ccb_core_group post type fields.
     *
     * @param array $post_type_maps A collection of all mappings currently in use
     *
     * @return array
     */
    function ccb_core_customize_group_fields( $post_type_maps ) {
    	if ( ! empty( $post_type_maps['ccb_core_group']['fields'] ) ) {
    		$post_type_maps['ccb_core_group']['fields']['user_defined_fields'] = 'post_meta';
    		$post_type_maps['ccb_core_group']['fields']['leaders'] = 'post_meta';
    		$post_type_maps['ccb_core_group']['fields']['membership_type'] = 'post_meta';
    	}
    	return $post_type_maps;
    }
    add_filter( 'ccb_core_synchronizer_post_api_map', 'ccb_core_customize_group_fields', 20, 1 );

    The main thing to note is that the name of the XML node (for example user_defined_fields needs to be defined as a property of the fields array which is a property of the ccb_core_group array.

    You can even override / remove some of the default mappings. For example, you can map something else to the post content like so (instead of the description):

    // Override the post content with the calendar feed
    $post_type_maps['ccb_core_group']['fields']['calendar_feed'] = 'post_content';

    The value of the item you add can be any property that exists on a WP_Post object (like ‘post_title, ‘post_content’, etc) or can be ‘post_meta’ (which saves it as a custom field).

    That $post_types_maps variable has many more configuration options in it (that you can customize with this filter). More info here: https://github.com/jaredcobb/ccb-core/wiki/Custom-Post-Types#get_post_api_map-maps- on what that array contains.

    • This reply was modified 2 years, 9 months ago by Jared Cobb.
    Plugin Author Jared Cobb

    (@jaredcobb)

    I forgot to mention, if you alter the mappings, the plugin won’t be aware that your data needs to be synchronized again.

    For example, it’s going to think that your Groups are “up to date” and it won’t try to fetch new data.

    In a situation like this, you’ll need to delete all your Groups from WordPress and then synchronize back from CCB after you’ve made your changes.

    Thanks for the quick reply Jared. So the user defined fields seems to be somewhat working Let me try to explain.

    <user_defined_fields>
    <user_defined_field>
    <name>udf_2</name>
    <label>Type of Group</label>
    <selection id="1">Trailguide</selection>
    <admin_only>false</admin_only>
    </user_defined_field>
    <user_defined_field>
    <name>udf_3</name>
    <label>Kids?</label>
    <selection id="2">Adults Only</selection>
    <admin_only>false</admin_only>
    </user_defined_field>
    </user_defined_fields>

    This is the information in my CCB XML. After installing the POST META INSPECTOR plugin I see user defined fields as this.
    'a:1:{s:18:"user_defined_field";a:4:{s:4:"name";s:5:"udf_3";s:5:"label";s:5:"Kids?";s:9:"selection";s:11:"Adults Only";s:10:"admin_only";b:0;}}'

    I deleted the groups out and resync’d them like you suggested. The leaders and participants just show up blank but I’m assuming it is because there are multiple options like the user defined fields. Again I may be asking too much and it isn’t necessary for me to complete my mission but I was trying to add some sort of display of who was in the group on my custom post type I created.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Extra data’ is closed to new replies.