Skip Navigation

[Resolved] checkbox wp field

This support ticket is created 5 years, 5 months ago. 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Shane 5 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1332803
unnamed-2.png

I'm using the tssupp_populate_user_field function to auto-populate a select field with all the posts from a custom post type. The name for the select field is 'member office location' and my custom post type is Office. This is how I'm using it:

I can't, however, auto-populate a checkbox or a multiple option checkbox with this same function. I've researched and nothing seems to work. Do you have a solution for this or is it a way you can help me with this?

Thanks in advance

#1332933

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Cooper,

Thank you for getting in touch.

This is actually an undocumented function meant to be used internally only. However I know this works for Select fields. I'm not so sure if this works for checkbox fields.

However could you try it like this.



add_filter( 'wpt_field_options', 'populate_select', 10, 3);
function populate_select( $options, $title, $type ){
    switch( $title ){
        case 'Member Office Location':
            $options = array();
			$args = array(
                'post_type'        => 'office',
                'post_status'      => 'publish');

            $posts_array = get_posts( $args );
            foreach ($posts_array as $post) {
                $options[] = array(
                    '#value' => $post->post_title,
                    '#title' => $post->post_title,
                     );
                }
               
                break;
}
    return $options;
}

Our assistance on undocumented or unofficial API code is limited.

Please try this and let me know.

Thanks,
Shane

#1335499

Hi Shane,

Thanks for your assistance, Could you help me out with a version with checkboxes instead of select?

Thanks in advance,
Cooper

#1335543

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Cooper,

Unfortunately no I wouldn't be able to assist with this because this is actually out of our support forum scope.

This is because there isn't an official hook that is available to do this. For this to be possible we would need to look into the code that the developers created to find the function that they are using.

Which would not be recommended because this function can get deprecated at any time. So unfortunately this wouldn't be possible for me to do.

However what I can do is to open a ticket with our 2nd tier supporters to see if they have a solution for this .

Thanks,
Shane

#1336959

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Cooper,

As suspected there isn't a hook for this and its now been confirmed by our 2nd tier supporters.

What I would recommend that you do is to open a feature request for this.
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

This way it can get added to the fields API but for now this isn't possible.

Thanks,
Shane