If you are having a notice about writing the .mo files please read this doc

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 1 reply, has 2 voices.

Last updated by Radu 2 months, 1 week ago.

Assigned support staff: Radu.

Author Posts
September 11, 2019 at 5:51 pm #4555663

Joeri

I want to populate (pre render) the checkbox field choices with the post titles from a custom post type. I already had this working using the documentation on: hidden link

Now that I have setup WPML for an additional language (I have Dutch as my default and English as additional) and have translated these posts, at first the checkbox field choices were populated with the post titles from both languages.

When I added suppress_filters=0 the checkbox field choices were again only populated with the post titles from one language (default language). This is good for one form but for my English form I want the get the translated English post titles.

Can you maybe help me out how to do this?

The code that I am using is:

add_filter( 'gform_pre_render_7', __NAMESPACE__ . '\\populate_trainings_checkbox' );
add_filter( 'gform_pre_validation_7', __NAMESPACE__ . '\\populate_trainings_checkbox' );
add_filter( 'gform_pre_submission_filter_7', __NAMESPACE__ . '\\populate_trainings_checkbox' );
add_filter( 'gform_admin_pre_render_7', __NAMESPACE__ . '\\populate_trainings_checkbox' );
function populate_trainings_checkbox( $form ) {

foreach( $form['fields'] as &$field ) {

$field_id = 1;
if ( $field->id != $field_id ) {
continue;
}

$posts = get_posts( 'post_type=training&numberposts=-1&post_status=publish&suppress_filters=0' );

$input_id = 1;
foreach( $posts as $post ) {

if ( $input_id % 10 == 0 ) {
$input_id++;
}

$choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );
$inputs[] = array( 'label' => $post->post_title, 'id' => "{$field_id}.{$input_id}" );

$input_id++;
}

$field->choices = $choices;
$field->inputs = $inputs;

}

return $form;
}

September 12, 2019 at 10:28 am #4560229

Radu
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hey,

Thank you for reaching out the WPML support!

I just checked this out, looked at the article you attached, but I couldn't find a simple way to make the code work for the translations. Since this is some custom coding (and this is outside of our support scope), you can try to reach out one of the WPML contractors (here you can find some more details https://wpml.org/contractors/) in order to make this work as you want.

Thanks,
Radu

The topic ‘[Closed] Populate a checkbox field (choices) with post titles from specific language’ is closed to new replies.