Home › Forums › General Issues › Select field from user profile
I want to create a select field that is attached to the user role which, in itself is simple enough, but I’m unsure how to output this. Ideally, both label and value.
The docs suggest the following;
<?php
$field = get_field_object( 'color' );
$value = $field['value'];
$label = $field['choices'][ $value ];
?>
<p>Color: <span class="color-<?php echo esc_attr($value); ?>"><?php echo esc_html($label); ?></span></p>
How would I now amend this so it works for fields within a user profile?
I’m doing something like this for other fields;
<?php
$repeater = get_field('invoices', 'user_' . $current_user->ID);
$order = array();
foreach( $repeater as $i => $row ) {
$order[ $i ] = $row['invoice_number'];
}
array_multisort( $order, SORT_DESC, $repeater );
if( $repeater ): ?>
<?php foreach( $repeater as $i => $row ): ?>
<tr>
<td><?php echo $row['invoice_number']; ?></td>
<td><?php echo $row['invoice_date']; ?></td>
<td><?php echo $row['invoice_total']; ?></td>
<td class="invoice-actions">
<div>
<a target="_blank" href="<?php echo $row['invoice']; ?>" ><i class="fa-regular fa-eyes"></i></a>
<a href="<?php echo $row['invoice']; ?>" download><i class="fa-regular fa-cloud-arrow-down"></i></a>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
But I’m confused as to why this method doesn’t work on the select field.
You need to add the post ID to the get_field_object() call just like you’ve added it to this line in your other code.
$repeater = get_field('invoices', 'user_' . $current_user->ID);
I’ve no idea why this didn’t work before, but it is working now.
Thanks John 👍
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.