Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1404923
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 questionI'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 questionI'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 |1 Answer
Reset to default 0I 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)
版权声明:本文标题:php - Output ACF repeater on frontend user's profile page (created with Ultimate Member) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744871586a2629658.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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 youracf_repeater()
, shortcode function should return the text that is to be displayed. – nmr Commented Dec 29, 2019 at 21:24