admin管理员组

文章数量:1404923

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

I'm using Ultimate Member plugin to manage my user directory. I also use Advanced Custom Fields to create some custom fields on the backend of the user's profile page (location: user form > equal > add/edit) which I want to output via shortcode on the profile page of the current user.

This is what I tried:

function acf_repeater() {

um_fetch_user( get_current_user_id() ); {

  if( have_rows('repeater_name') ):

    while ( have_rows('repeater_name') ) : the_row();

      the_sub_field('subfield_name');

    endwhile;

  else :

  endif;
  } 
}

add_shortcode('acf_repeater_shortcode', 'acf_repeater');

but this doesn't work. Any tips?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

I'm using Ultimate Member plugin to manage my user directory. I also use Advanced Custom Fields to create some custom fields on the backend of the user's profile page (location: user form > equal > add/edit) which I want to output via shortcode on the profile page of the current user.

This is what I tried:

function acf_repeater() {

um_fetch_user( get_current_user_id() ); {

  if( have_rows('repeater_name') ):

    while ( have_rows('repeater_name') ) : the_row();

      the_sub_field('subfield_name');

    endwhile;

  else :

  endif;
  } 
}

add_shortcode('acf_repeater_shortcode', 'acf_repeater');

but this doesn't work. Any tips?

Share Improve this question asked Dec 8, 2019 at 11:13 Chris OsiakChris Osiak 117 bronze badges 2
  • By default have_rows() check to see if current post has any row. You should pass user ID, in format "user_{$user_id}", as a second parameter. Take a look at "Get values from a user". And don't display anything in your acf_repeater(), shortcode function should return the text that is to be displayed. – nmr Commented Dec 29, 2019 at 21:24
  • 3rd party plugin support is out of scope for WPSE. You should seek help from the plugin's official support streams. – nmr Commented Dec 29, 2019 at 21:25
Add a comment  | 

1 Answer 1

Reset to default 0

I managed to find a solution - perhaps it will be helpful for someone in the future... :)

This is function that will create a table similar to the repeater on the backend. In this case 4 columns - can be adjusted and styled as necessary.

function acf_repeater() {

$user_id = get_current_user_id();
ob_start(); ?>
<?php if( have_rows('repeater_name',"user_{$user_id}" ) ): ?>

<table>
   <tr>
    <td>Column 1 header</td><td>Column 2 header</td><td>Column 3 header</td><td>Column 4 header</td>
   </tr>

<?php while ( have_rows('repeater_name', "user_{$user_id}" ) ) : the_row(); 

    // vars
    $var1 = get_sub_field('subfield_1_name');
    $var2 = get_sub_field('subfield_2_name');
    $var3 = get_sub_field('subfield_3_name');
    $var4 = get_sub_field('subfield_4_name');

?>
    <tr>
        <td><?php echo $var1; ?></td><td><?php echo $var2; ?></td><td><?php echo $var3; ?></td><td><?php echo $var4; ?></td>
    </tr>


<?php endwhile; ?>

</table>
<?php else: echo '<span>No data</span>'; ?>
<?php endif; ?>
<?php $output = ob_get_clean();
return $output;
}

add_shortcode('acf_repeater_shortcode', 'acf_repeater');`

本文标签: phpOutput ACF repeater on frontend user39s profile page (created with Ultimate Member)