Skip Navigation

[Resolved] Can I make relationship between My Custom post Type and User??

This support ticket is created 9 years, 4 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 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 10:00 – 19:00 -
- - - - - - -

Supporter timezone: Europe/Madrid (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by feimingH 9 years, 4 months ago.

Assigned support staff: Caridad.


I met a problem that I custom a post type for all user in the wordpress system. and the post type is a many-to-many relationship of user.
Can I make the relationship between My Custom post Type and User??


Dear Feiming,

You can't do that directly. We will be adding support for this in a future release but for now you have to rely on workarounds. You can create a custom post type that has a one-to-one relationship with users, you could call it Profile. From the you can follow the normal procedure for many to many relationships.

Lets say your Profile custom post type has a "user_id" field to connect it to the user. To create a Profile for each user you can add these lines to functions.php in your theme:

function your_function($user_login, $user) {
    $profile = get_posts( array( 'post_type' => 'profile', 'wpcf-user_id' => $user->ID ) );
    if ( empty( $profile ) ) {
      $id = wp_insert_post( array( 'post_type' => 'profile', 'post_title' => $user->display_name, 'post_status' => 'publish' ) );
      add_post_meta( $id, 'wpcf-user_id', $user->ID );
add_action('wp_login', 'your_function', 10, 2);

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.



Sorry for the delay.
Your answer realy helpful.