Hi,
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.
Regards,
Caridad
Sorry for the delay.
Your answer realy helpful.