• I need a little help, if anyone can!

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Are the ACF field ‘users’ actual WordPress users? Or they are just a custom meta of that post?

    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 ??

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘ACF & CPT Private Post’ is closed to new replies.