Hi,
Thank you for sharing the access details.
In order to dynamically populate the options of the "Vehicle Location" field from the posts from the CPT "TMNA Locations", you'll need to use the filter "wpt_field_options":
https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options
Example:
add_filter( 'wpt_field_options', 'func_to_dynamically_populate_vehicle_locations', 10, 3);
function func_to_dynamically_populate_vehicle_locations( $options, $title, $type ){
switch( $title ){
case 'Vehicle Location':
$options = array();
// add first empty value
$options[] = array('#value' => '', '#title' => '---');
// get all tmna-location post items
$args = array( 'post_type' => 'tmna-location', 'posts_per_page' => -1, 'post_status' => 'publish','orderby' => 'title' );
$results = get_posts( $args );
if ( $results ) {
foreach ( $results as $post ) {
$options[] = array('#value' => $post->ID, '#title' => $post->post_title);
}
}
break;
}
return $options;
}
As a result, when you'll check the "Vehicle Location" field on the "Vehicle" post edit screen or in the form for the "Vehicle" post type, you'll see "TMNA Locations" posts in its select/dropdown.
On form's submission, the selected "TMNA Locations" post will be automatically saved in the "Vehicle Location" field, but if you'd also like to create a relationship between this new "Vehicle" post and the selected "TMNA Locations" post, you'll need to use "toolset_connect_posts" function ( ref:https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts ) through "cred_save_data" hook ( ref: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data ).
Example:
add_action('cred_save_data','func_connect_child_posts',15,2);
function func_connect_child_posts($post_id,$form_data) {
if ($form_data['id']==1234) {
if(!empty($_POST['wpcf-vehicle-location'])) {
toolset_connect_posts( 'tmna-location-vehicle', $_POST['wpcf-vehicle-location'], $post_id );
}
}
}
Note: You'll replace 1234 with the actual form's ID.
As for the issue with the code snippet from my previous message, I couldn't reproduce this on my test website.
I'll recommend to turn on WordPress debugging and see if any errors or warnings are shown on the screen or in the server's error logs.
( ref: https://wordpress.org/support/article/debugging-in-wordpress/ )
regards,
Waqar