Skip Navigation

[Resolved] Cred Select Country Field – Needs to be editable in WordPress Edit User

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by iainF 5 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1258697

We've created a Cred Generic field which uses a shortcode "[credcountries]" for the user to select their country from on a User Form:

<div class="form-group">
<label>Country<span class="req">*</span></label>
[cred_generic_field type='select' field='wpcf-country' class='form-control']
{
"default": "[types usermeta='wpcf-country' output='raw' user_is_author='true'][/types]",
"required":1,
"persist": 1,
"options":[ [credcountries] ]
}
[/cred_generic_field]
</div>

This all works great, but when the site admins try to edit the user on the backend, a select box is just displayed with two options:
"--- not set ---"
"Option title 1"

Is there any way or documentation where we can get the items that we generate in the "credcountries" shortcode to appear in the standard WordPress "Edit User" form?

Best Regards

Iain

#1259131

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - to fill the value for your custom user field you can use the filter: wpt_field_options

For example:

add_filter( 'wpt_field_options', 'add_some_options', 10, 3);
//dynamically populate select field from Types
function add_some_options( $options, $title, $type ){
    switch( $title ){
        case 'Status':
          
            $options = array();
            $speakers = get_users(array( 'role' => 'Subscriber' ));
          
            foreach ($speakers as $user) {
                $options[] = array(
                    '#value' => $user->ID,
                    '#title' => $user->user_login,
                );
            }
            break;
    }
    return $options;
}

Where:
- please replace Status with your user field name and adjust the code accordingly.

More info:
- https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

#1260331

Thank you.

I've now got this working.

Best Regards

Iain

#1260333

My issue is resolved now. Thank you!