Hi,
I have a repeatable field group that I display on the website. Here's an example: hidden link (Look for the available dates). Everything works great if I create a post from the admin page.
Now I have created a form where users can create their own posts. I did some custom coding to be able to support the repeatable field group. Here's the code that creates them:
add_action('cred_save_data', 'hvf_add_available_dates_to_company',10,2);
function hvf_add_available_dates_to_company($post_id, $form_data) {
if ($form_data['id'] == 23899) {
$availableDates = $_POST['available-date'];
foreach ($availableDates as $availableDate) {
// the data comes in the following format: "d/m/Y to d/m/Y"
[$startDate, $endDate] = explode(' to ', $availableDate);
$startDateTimestamp = DateTime::createFromFormat('!d/m/Y+', $startDate)->getTimestamp();
$endDateTimestamp = DateTime::createFromFormat('!d/m/Y+', $endDate)->getTimestamp();
$args = array(
'post_title' => 'Available Date ' . $availableDate . ' for '. $post_id,
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'available-dates',
'meta_input' => array(
'wpcf-start-date' => $startDateTimestamp,
'wpcf-end-date' => $endDateTimestamp,
)
);
// create the available dates
$availableDateId = wp_insert_post( $args );
toolset_connect_posts( 'available-dates', $post_id, $availableDateId );
}
}
}
The code runs without a problem. When I look at the post on the admin page, I see that the association is created without any problem. But when I look at the page where I display the data, I see that it wouldn't be displayed ("coming soon" is the message I display when no item is found).
I wonder if there's a problem the way I create the association or is there a cache problem going on. How can I understand what is wrong with the code or the view?