Skip Navigation

[Resolved] Save field options generated via php to database.

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.

This topic contains 1 reply, has 2 voices.

Last updated by Christopher Amirian 2 years ago.

Assisted by: Christopher Amirian.

Author
Posts
#2517557
Screenshot 2022-12-17 at 2.50.10 PM.png

Tell us what you are trying to do?
I am trying to insert field options of a 'select' field of CPT B from titles of CPT A. So far i have been able to get the options to show up on the front end. however on inspecting the specific post field of CPT B on the backend, the options are still empty.

How can I get the options to be saved into the database? So that they are available in the post field editor?

Thank you for your time!

An example of the codes as follows:

// fill Breed custom field select options dynamically
add_filter( 'wpt_field_options', 'func_fill_select_breeds', 10, 2);
function func_fill_select_breeds( $options, $title ){
switch( $title ){
case 'Breed':
$options = array();
$args = array(
'post_type' => 'breeds',
'post_status' => 'publish',
'numberposts' => -1,
);
$ps_array = get_posts( $args );
foreach ($ps_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,);
}
break;

}
return $options;
}

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

Is there a similar example that we can see?

What is the link to your site?

#2518225

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

To do that you need custom development which is outside of our support scope.

You will need the save data hook and for the documentation you can check:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

For more information about your options with forms API:

https://toolset.com/documentation/programmer-reference/cred-api/

And

https://toolset.com/forums/topic/saving-value-from-standard-generic-form-field-to-a-custom-field-in-cpt/#post-1489201

Thanks.