If I can understand what you are looking for, you can create a simple function, that will fire when a new of the CPT is created and update a post_meta eg: "user_controler" for that.
Later, you will need to filter, the posts on the post.php
, to show posts only related to the current user.
add_action("save_post", function ($post_ID, $post){
$post = get_post($post_ID);
$user = get_curent_user();
if($post->post_type === "my_cpt" && !get_post_meta($post_ID, "my_meta_key")){
update_post_meta($post_ID, "my_meta_key", $user->key);
}
//$user->key matches what you want to kip as link.
});
To filter the posts on the post.php
page you can:
add_filter( 'posts_results', 'my_posts_results_filter' );
function my_posts_results_filter( $posts ) {
global $my_global_condition;
$user = get_curent_user();
$screen = get_current_sreen();
$filtered_posts = array();
foreach ( $posts as $post ) {
if (
$post->post_type === "my_cpt" &&
$screen->ID === $my_cpt &&
get_post_meta($post_ID, "my_meta_key")=== $user->key
) {
// It's allow :).
$filtered_posts[] = $post;
}
}
return $filtered_posts;
}
You can also use post_where filter.
You can also filter post simple base on the author property.
With 💕.