Navigation überspringen

[Gelöst] set value in a CRED field

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
How to set value in a CRED field

Solution:

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/set-value-in-a-cred-field/#post-841202

Relevant Documentation:

This support ticket is created vor 6 Jahren, 7 Monaten. 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.

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)

Dieses Thema enthält 1 Antwort, hat 2 Stimmen.

Zuletzt aktualisiert von Minesh vor 6 Jahren, 7 Monaten.

Assistiert von: Minesh.

Author
Artikel
#840401

Hello, I explain my problem:

I have this input form:

[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');

Thanks.

#841202

Minesh
Supporter

Sprachen: Englisch (English )

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

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');