Support

Account

Home Forums ACF PRO Display fields group if user is logged in

Helping

Display fields group if user is logged in

  • Hi,

    I would like to display a field group if a user is logged in.

    My ultimate goal is :
    1 – Create a CPT : Done
    2 – Create multiple users : Done
    3 – Create a select displayed in each user profile that show all posts from my CPT : Done
    4 – Show post content which was assigned to the user : How ?

    This is my select :

    function add_extra_user_fields( $user ) {
        
        $userid = get_user_meta($user->ID);
        $args = array(
            'post_type' => 'promotion',
            'posts_per_page' => -1,
        );
        
        $query = new WP_Query($args);
        
        ?>
        
        
        <table class="form-table">
            <tbody>
                <tr>
                    <th>
                        <label for="">Assigner un programme</label>
                    </th>
                    <td>  
                        <select name="testprofile">
                            <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
    
                                <option value="<?php the_ID(); ?>">
    
                                    <?php
                                    if (get_user_meta( $userid, userphotos, true) == $userid ){ 
                                        echo 'selected'; 
                                    }
                                    ?>
    
                                    <?php the_title(); ?>
    
                                </option>
                            <?php endwhile; endif; ?>
                        </select> 
                    </td>
                </tr>
            </tbody>
        </table>
    
        <?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' );
  • Hi WDCreativ,

    I’m not sure about what you need, you’re talking about displaying a field group to logged in user and about showing post content which was assigned to the user. Can you tell me more ?

    What do you want to display : CPT Content ? Field Group ? …
    Where : In backend ? Frontend ? On user profile ? On CPT ? …
    With wich rules : Display it if you assign user to the CPT ? When user select the CPT ID with the select field ? …

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Display fields group if user is logged in’ is closed to new replies.