[credform class='cred-form cred-keep-original']
<div class="form-group">
<label>Universidad Popular que contrata</label>
[cred_field field='_wpcf_belongs_universidad-popular_id' value='[id_univ_usuario]' required='true' class='form-control' output='bootstrap']
</div>
[/credform]
I want to auto select the field. The shortcode [id_univ_usuario] return the ID of the custom field that I want to auto select, but the field display "not-select".
My shortcode code is:
// Get 'CPT Universidad Popular' ID of the user login.
function jm_id_univ_usuario(){
global $current_user;
$args = array(
'post_type' => 'universidad-popular',
'author' => $current_user->ID,
'status' => 'publish',
);
$id_universidad = get_posts( $args );
echo $id_universidad[0]->ID;
}
add_shortcode ('id_univ_usuario', 'jm_id_univ_usuario');
Hello. Thank you for contacting the Toolset support.
Well - you are echoing the ID from your shortcode. Instead of echoing, you should return the id.
Could you please try following code:
[credform class='cred-form cred-keep-original']
<div class="form-group">
<label>Universidad Popular que contrata</label>
[cred_field field='_wpcf_belongs_universidad-popular_id' value='[id_univ_usuario]' required='true' class='form-control' output='bootstrap' use_select2="never" ]
</div>
[/credform]
Where:
- we set the shortcode to not to use select2.
Instead of echo - return the Id.
// Get 'CPT Universidad Popular' ID of the user login.
function jm_id_univ_usuario(){
global $current_user;
$args = array(
'post_type' => 'universidad-popular',
'author' => $current_user->ID,
'status' => 'publish',
);
$id_universidad = get_posts( $args );
return $id_universidad[0]->ID;
}
add_shortcode ('id_univ_usuario', 'jm_id_univ_usuario');