Home Forums ACF PRO If current user exists in a repeater field of users?


If current user exists in a repeater field of users?

  • First off, my coding skills are upper white belt at best.

    I’m trying to allow only certain users to edit a pages content that essentially has no set author per say via front page AFC form.

    I’ve created a repeater “content_editors” that is made up of users that the admin can add to a given post/page.

    So I’m thinking of a way to do something like the following:

    If current user ID matches an ID in the “content_editors” repeater,
    Show the front end form.

    Any recommendations on whats the best way to accomplish this?

    I’ve gotten as far as getting the ID’s from the repeater.

    // check if the repeater field has rows of data
    if( have_rows('content_editors') ):
      // loop through the rows of data
        while ( have_rows('content_editors') ) : the_row();
          $user_id = get_sub_field('editor_user')[ID];
            // display a sub field value
    else :
        // no rows found
    echo 'nada';

    Also I’ve been able to show the form based on is author or custom role.
    The issue is using a role(s) isn’t granular enough.

    // set vars
    $postAuthor = $post->post_author;
    $currentUserID = get_current_user_id();
    // if user is match
    if ( $postAuthor == $currentUserID OR current_user_can('administrator') OR in_array( 'site_contributor', (array) $current_user->roles ) ) { 
      'post_title'  => true,
      'post_content' => true,
      //'field_groups' => array('group_576d54e22b7bb'),
      'fields' =>  array('year','pub_date','pub_type','pub_keywords','pub_url','pub_publisher','published_meta','pub_authors','pub_contact','pub_contacts','local_file','pub_gallery','afc_featuredImage'),
      'submit_value'  => 'Save Changes'

    Any information is greatly appreciated, thanks in advance.

  • Anyone?

    How can I check if a user exists in a repeater?

  • I think you might be helped by reading this topic.

    I think I just explained something like this in the aforementioned topic.

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

The topic ‘If current user exists in a repeater field of users?’ is closed to new replies.