Skip Navigation

[Resolved] Dynamically Populate Checkbox Options

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)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 1 year, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2678987

Tell us what you are trying to do?

I am trying to populate checkbox options in the backend.

Is there any documentation that you are following?

I am using this code that I found in the support forums - which works for select options but doesn't seem to work for checkbox options.

add_filter( 'wpt_field_options', 'populate_affiliates_override', 10, 3);
function populate_affiliates_override( $options, $title, $type ){
switch( $title ){
case 'Applicable Affiliates':
$options = array();
$args = array(
'post_type' => 'partner',
'post_status' => 'publish',
'posts_per_page' => -1,
'numberposts' => -1,
'orderby' => 'title',
'order' => 'ASC'
);

$posts_array = get_posts( $args );
foreach ($posts_array as $post) {

$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}

break;
}
return $options;
}

#2679047

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Checkboxes are a quite special field type that stores its value as serialized array in to the database.

There is no such way to dynamically populate the checkboxes fields.

#2679162

Hmmm. So it is only possible to populate them on the front end then?
https://toolset.com/forums/topic/auto-populate-checkboxes-field-with-custom-post-type-title/

If it is not possible to populate them on the backend, is there a different field we can dynamically populate that allows more than 1 selection?

#2679429

Minesh
Supporter

Languages: English (English )

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

Yes - that's different thing and its using Toolset form using Generic field.

Unfortunately there is no way to auto-populate the checkboxes field in the backend.

If it is not possible to populate them on the backend, is there a different field we can dynamically populate that allows more than 1 selection?
==>
What if you create a many-to-many post relationship or one to many post relationship which suites your need, will that work?