Navigation überspringen

[Gelöst] Dynamically Populate Checkbox Options

This support ticket is created vor 2 years, 4 months. 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 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 3 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Minesh vor 2 years, 4 months.

Assistiert von: Minesh.

Author
Artikel
#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
Unterstützer

Sprachen: Englisch (English )

Zeitzone: 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
Unterstützer

Sprachen: Englisch (English )

Zeitzone: 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?