Using ACF Pro, and CPT, I have made a front end form where an admin can choose a user name and other specific information, then click submit and the post is published.
What I want to do now, is only allow the chosen user to see that post as long as they are logged in. Meaning, the chosen user is logged in and can only see the new post that has their name selected.
Thanks in advance! I’ve tried just about everything.
]]>In either case the idea would be similar. You can make a custom template for that specific post type ( or page ) and add your queries at the top.
You could try for example first checking if the user is logged in then if the posts meta corresponds to that user and act accordingly, a wide example ( as I don’t know your fields and set up ) could be something like:
<?php
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
$post_user_id = get_field( 'your_meta_key' );
if ( $user_id === $post_user_id ) {
// do whatever
} else {
// do something else maybe
}
} else {
echo 'You have to log in to view this page!';
}
This should be inside your post loop. If you want it first on the page you have to get the posts ID as well to check for the correct meta.
Like I said this is a bit vague as I don’t know what you want exactly to show or redirect etc but I’ve done the similar idea on one of my clients and it works fine ??
]]>Using ACF Pro
You really need to ask the vendor for support.
For pro or commercial product support please contact the author directly on their site.
https://support.advancedcustomfields.com/
As the author is aware, commercial products are not supported in these forums. As you are their customer I am sure they will have no problem supporting you there.
]]>