Skip Navigation

[Closed] Relationship Post

This support ticket is created 4 years, 8 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Shane 4 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1570861

Hi, My project has three relate post types.

Account
User
Session

The setup is simple. An account has users that take part in sessions.

I want to be able to create accounts, which forwards you to the new Account post. On the account post I want to be able to add users under the account, then do the same by adding sessions to the user.

The fields for user are first name and last name. They are assigned to user post type.

When I create a relationship form for Account -> User, when I get to the form builder screen, the fields first name and last name are not an option. In the docs it seems like they should be available.

I tried to add them manually and nothing happened.

What am I missing here?

#1571197

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

Thank you for getting in touch.

I'm assuming that Account and User are 2 post types that you've created correct?

Are there any relationship fields between them ? Also is this a many to many relationship ? The reason I asked is because with One to Many relationships you don't need to create a relationship form.

Please provide me with some additional information so that I can best advise.

Thanks,
Shane

#1571517

Hi Shane,

Yes, account, user, session are all post types. The relationships are both one to many. Each account can have many users and each user can have man sessions.

So I can simply css display none the field to pick the parent and I'm fine?

I have another question also. I would like to use the cred_save_data action to change the name of the session post.

I'd like to name the post the date, which is working, and then then data from custom fields in the parent.

Below you'll see I added wpcf-client-first-name. However I'm only the date i the post title. Do I need to call that data a different way?

Thank you

add_action('cred_save_data', 'my_save_data_action2',10,2);
    
   function my_session_save_action($post_id, $form_data){
            // Change your CRED Form "ID" accordingly below
            if ($form_data['id']==28){
                
                //Declare the content of your variables, change "your_custom_field_slug" accordingly
                $first = get_post_meta( $post_id, 'wpcf-client-first-name', true );
				$last = get_post_meta( $post_id, 'wpcf-client-last-name', true );
				$date = get_post_meta( $post_id, 'wpcf-session-date', true );
				    $formated_date = date("M j y", ($date));
				$custom_title = $formated_date.' '.$last.' '.$first;
                
                //collect data and define new title
                $my_post = array(
				'ID' => $post_id,
				'post_title' => $custom_title,
				'post_name' => $custom_title,
                    
                );
                
                // Update the post into the database
                wp_update_post( $my_post );
                
            }
        }
    add_action('cred_save_data', 'my_session_save_action',10,2);

New threads created by Shane and linked to this one are listed below:

https://toolset.com/forums/topic/split-relationship-post/

#1572427

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

When I create a relationship form for Account -> User, when I get to the form builder screen, the fields first name and last name are not an option. In the docs it seems like they should be available.

Given that the relationship is a one to many relationship then the fields should be available when you create the form. Just to be clear this is a regular post form and not a relationship form.

This means you go to Toolset -> Post Form and add a new form from there.

Could you send me a screenshot of the Form ? Given that you say the first name and last name fields should be on the user CPT then the form should be a Post form for Users.

For your second issue I've split it into a separate ticket as we only handle one query per support thread.

Thanks,
Shane

The topic ‘[Closed] Relationship Post’ is closed to new replies.