Skip Navigation

[Resolved] Connecting Two CPT’s with intermediary CPT via CRED New Form

This thread is resolved. Here is a description of the problem and solution.

Connecting Two CPT's with intermediary CPT via CRED New Form

You can use CRED hook "cred_save_data" to do any customization you
need and to connect the post using intermediary post entry.

You can find proposed solution, in this case, with the following reply:

Relevant Documentation:

This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)


So from this support post that Minesh was the support person for.

I need to be able to do the same thing but with a CRED New Post Form. The latter works only for existing CRED Post forms.

Thank you,
Ronald E



Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - to adjust the code for your add form - I've added the generic field to your add form as given under:

[cred_generic_field field='_wpcf_belongs_member_id' type='select' class='' urlparam='']
{"value":"0","label":"Select Member Profile"},[wpv-view name="member-profile-list"]

Then, I've adjusted the code that is added to current theme's functions.php as given under:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '3679' || $id == '3633' ) {
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if ( 
            $start !== false
            && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
        ) {
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '<!-- wpv-loop-end -->' );
            $out = substr( $out, 0, $end );
    return $out;

function func_add_writer($post_id,$form_data) {
	global $current_user;
    if ($form_data['id']==3651) {
		// fetch existing writer posts and delete it
		$result = get_posts(array(
							'fields' => 'ids',
							'post_type' => 'writer',
							'meta_query' => array(
								   'key' => '_wpcf_belongs_article_id',
								   'value' => $post_id,
		if(count($result) > 0) {
			foreach($result as $k=>$v):
	if ($form_data['id']==3651 or $form_data['id']==3633) {
	    // add new writer 
		  $data_arr = array(
				'post_title'=> "writer for article ".$post_id,
				'post_type' => 'writer',
				'post_status' => 'publish',
				'post_author' => get_current_user_id(),
		$insert_post_id = wp_insert_post($data_arr);
        update_post_meta($insert_post_id, '_wpcf_belongs_article_id',$post_id);
		update_post_meta($insert_post_id, '_wpcf_belongs_member_id',$_POST['_wpcf_belongs_member_id']);

Could you please confirm it works for both of your add and edit form now.


Thank you Minesh! This should be a feature of the Toolset Product. What you coded would be used by lots of people with Membership accounts wanting to link to articles via an intermediary post type relationship. What you did was make for a very nice user experience outside of WordPress with Toolset Cred and Access. Much better then haveing them go into the WP admin and find the right post type, scroll down to the bottom of the page, and then figure out how to use the relationship editor.

Thank you again and remember, contact me when you are in Seattle and we'll eat dinner in the Space Needle.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.