Skip Navigation

[Resolved] Creating a custom post type with CRED and user registration at the same time

This support ticket is created 5 years, 11 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)

Author
Posts
#1182130

Tell us what you are trying to do?
I have a custom post type "Attendees", I want the user be able by using CRED to connect to the corresponding post type Attendees and register to the website as well I will create a role with Access.

Is there any documentation that you are following?
I read some but I need help from you

What is the link to your site?
hidden link (Toolset Form and post type not created yet...)

Many thanks
Roberto Ciccolella

#1182239

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - do you want to create custom post type or just custom post for a specific post type, in this case, it will be Attendees - correct?

#1182243

I am creating the custom post type following my client requirements about which field to add.

Ideally I want this custom post type to be filled by the user him/her self by filling a front end form with CRED that will create the custom post type entry feeding the connected fields using CRED.

I also want in the same session that when the user submit the from he get also user and password by user registration.

Is this feasible or too complicate?

Thanks
Roberto

#1182274

Minesh
Supporter

Languages: English (English )

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

Well - there is no such feature available to create custom post type with the user registration form.

But - you can always add your custom needs using the Toolset Forms hook - cred_save_data.

You should try to use the WordPress standard function register_post_type() to add new post type using forms hook cred_save_data.
=> https://developer.wordpress.org/reference/functions/register_post_type/

More info:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

You can use following Doc to create user form:
=> https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-registering-users/

You can use the User Email notifications to send email to user with password:
=> https://toolset.com/documentation/user-guides/cred-user-forms-email-notifications/

#1182280

Oh my gosh this looks complicated I was wishing to have a no coding option.

Do you think I can simplify the process separating the 2 processes?

1) User register with CRED and get user and password

2) After registering he/she gets an email with a link to a CRED form connected with post type "Attendees" that when submitted will create the post.

About user registration I will need to add more user field with Types.

Do you think this way is easier with no coding involved?

Best Regards

Roberto

#1182287

Minesh
Supporter

Languages: English (English )

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

Yes - I think this way you just need to follow the Toolset forms docs and you will be able to achieve it.

How you can create user fields:
=> https://toolset.com/documentation/user-guides/user-fields/

Once you create user field group and added fields to it - When you create user form and click on "Auto Generate form content" button it will be available to use with user form.

#1182294

Thank you Minesh.

Will do the following:

1) Add fields to user
2) Assign a custom role with Access
3) Create the front end user registration form adding any custom field created.

My client will be manually creating for each registered user the custom post type entry so he will have like John, Sandra, Robert attendees post entry.

The advantage of user registration is that users can also update their profile at any time.
Do you think this is the way to go?

Cheers

#1182301

Minesh
Supporter

Languages: English (English )

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

1) Add fields to user
==> OK
2) Assign a custom role with Access
==> You should create a new role using access plugin and when you create a user form - from where you can select the role for the form. That means the new user will be created with that role.
3) Create the front end user registration form adding any custom field created.
=> Yes - correct.

My client will be manually created for each registered user the custom post type entry so he will have like John, Sandra, Robert attendees post entry.
=> Here do you mean that once user registered - you want to create/add a new entry (new post) for post type "Attendees"?

#1182309

Yes, ideally I wanted an automated system but I think is not a big deal for my client to create a new attendees post type entry for each attendees getting the info from user profile.

We need this post type since client wish to display for each Event all Attendees, I am using ONE TO MANY post relationship.

Do you have any idea to simplify the process without any complicate use of coding?

#1182310

Minesh
Supporter

Languages: English (English )

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

Well - if you just wanted to add entry its easy - not much code required.

You can use the Toolset Form hook - cred_save_data.

You can add the following code to your current theme's functions.php file.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {

    if ($form_data['id']==9999){
 
// Create new entry after registration.
$my_post = array(
  'post_title'    => $_POST['wpcf-field-name'],
  'post_content'  => '',
  'post_status'   => 'publish',
  'post_author'   => $post_id,
  'post_type' => 'attendees'
);
      
// Insert the post into the database
wp_insert_post( $my_post );
    }

Where:
- Replace 9999 with your user form ID
- Replace wpcf-field-name with original field name for which you want to create the entry

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1182327

This looks like the solution I was looking for , so by this hook when the user register can -in the same time fill or better feed the corresponding post type attendees?

Can you confirm?

I will create a code snippet using the same name plugin of the code your provided me since Oxygen do not have a functions.php file

Many thanks Minesh

#1182328

Minesh
Supporter

Languages: English (English )

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

Yes - it will create a new entry automatically once user registered.

There is no need to create a plugin - you can add your custom code to "Custom Code" section. Please check the following doc:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1182336

My issue is resolved now. Thank you!