Link users to a custom post type

if you are trying to link up the post in the user profile area, the code below might be a good starting point. You could put this in your functions.php file. The first function displays a select tag with all the posts from your custom post type in the user profile section. The option value is the post id, and the title is the post name. The next function saves the user profile information, adds or updates a user meta field(in this case, I used ‘userphotos’ that will store the ID of the post. When you want to display the user’s posts anywhere on the site, you can use WP_User_Query, and display the user’s metadata. If you are looking to include multiple posts, a check box or use the multiple attribute in the select tag, and store the posts as an array in the metafield. The code below isn’t tested, and wasn’t quite sure how you wanted the user profile section to function, so apologies if this isn’t what you are looking for.

<?php
function add_extra_user_fields( $user ) {
    $userid = get_user_meta($user->ID);
    $args = array(
     'post_type' => 'your_post_type',
     'posts_per_page' => -1,
    );
    $query = new WP_Query($args);
    ?>
    <select name="testprofile">Select a Post</p>
    <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
        <option value="<?php the_ID(); ?>" 
        if (get_user_meta( $userid, userphotos, true) == $userid ){ 
            echo 'selected'; 
        }?>>
        <?php the_title(); ?>
        </option>
    <?php endwhile; endif; ?>
    </select>
    <?php
}

add_action( 'show_user_profile', 'add_extra_user_fields' );
add_action( 'edit_user_profile', 'add_extra_user_fields' );

function save_extra_user_fields( $user_id ) {
    update_user_meta( $user_id, 'userphotos', sanitize_text_field( $_POST['testprofile'] ) );
}

add_action( 'personal_options_update', 'save_extra_user_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_fields' );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)