As part of this project i have already created an Institute custom post type which i can see in the admin dashboard.
What i want to do now is link it to the registration form. The logic is that when a user registers there will be an Institute field. In that Institute field they will write their Institute name.
I just want to try and get this to work before thinking about duplicates, variation spelling etc.
When they hit Submit, that Institute name will go on to create a post in the Institute custom post type that we will be able to see in the Admin dashboard.
The form is already set up, and this is the code iv been able to work out so far:
$my_institute = array (
'post_type' => 'Institute',
'post_title' => $_POST['field_12']['text'], /* field 12 is the text area */
'post_content' => 'This description is not needed',
'post_status' => 'publish',
);
wp_insert_post( $my_institute );
Is this correct, I was assuming it is straightforward and was going to copy and paste this.
As part of this project i have already created an Institute custom post type which i can see in the admin dashboard.
What i want to do now is link it to the registration form. The logic is that when a user registers there will be an Institute field. In that Institute field they will write their Institute name.
I just want to try and get this to work before thinking about duplicates, variation spelling etc.
When they hit Submit, that Institute name will go on to create a post in the Institute custom post type that we will be able to see in the Admin dashboard.
The form is already set up, and this is the code iv been able to work out so far:
$my_institute = array (
'post_type' => 'Institute',
'post_title' => $_POST['field_12']['text'], /* field 12 is the text area */
'post_content' => 'This description is not needed',
'post_status' => 'publish',
);
wp_insert_post( $my_institute );
Is this correct, I was assuming it is straightforward and was going to copy and paste this.
First, add the custom field to the registration form:
add_action( 'register_form', function(){
?>
<p>
<label for="institute">Institute</label>
<input type="text" name="institute" class="input" value="" size="25">
</p>
<?php
} );
Then, hook to user_register
action which gets called after a user has been registered succesfully.
add_action('user_register',function($user_id){
$my_institute = array (
'post_type' => 'Institute',
'post_title' => $_POST['institute'], // Custom field value
'post_content' => 'This description is not needed',
'post_status' => 'publish',
);
wp_insert_post( $my_institute );
});