Thank you for sharing all those required links and information and it was bit hard to locate where the issue was but finally happy to say that I found the issue.
Can you please try to create a new event now using the user "yusuf.soysal+halil@gmail.com":
- hidden link
Once you create the event - please check on the "my Camps" page:
- hidden link
Can you please confirm it's working as expected now? If yes:
- The issue was I've adjusted the code you added to your code snippet as given under:
- hidden link
add_action('cred_save_data', 'hvf_add_venue_and_available_dates_to_event',10,2);
/*
* This function is only intended to work when a logged in camp owner creates a camp
*/
function hvf_add_venue_and_available_dates_to_event($post_id, $form_data){
// if it is the add camp form
if ($form_data['id'] == 23899) {
// for some reason, event price is not updated for the event. let's fix that
//update_post_meta( $post_id, 'wpcf-event-price', $_POST['wpcf-event-price'] );
$availableDates = $_POST['available-date'];
$venueList = $_POST['selectedVenues'];
// ADDING EVENT STATUS BY DEFAULT
update_post_meta($post_id,'wpcf-event-status','ACTIVE');
// add available dates
foreach ($availableDates as $availableDate) {
[$startDate, $endDate] = explode(' to ', $availableDate);
if( $endDate == null ) {
$endDate = $startDate;
}
$startDateTimestamp = DateTime::createFromFormat('!d/m/Y+', $startDate)->getTimestamp();
$endDateTimestamp = DateTime::createFromFormat('!d/m/Y+', $endDate)->getTimestamp();
$order_item = 1;
$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,
'toolset-post-sortorder' => $order_item++
)
);
// create the available dates
$availableDateId = wp_insert_post( $args );
toolset_connect_posts( 'available-dates', $post_id, $availableDateId );
}
// add the venues
foreach ($venueList as $venueId ){
toolset_connect_posts( 'venue-event', $venueId, $post_id );
}
// associate with the company
$args = array(
'post_type' => 'company',
'numberposts' => 1,
'author' => get_current_user_id()
);
$companies = get_posts( array(
'post_type' => 'company',
'numberposts' => 1,
'author' => get_current_user_id()
) );
error_log("Companies: " . json_encode($companies));
if( $companies && count($companies) > 0 ){
toolset_connect_posts( 'company-event', $companies[0]->ID, $post_id );
}
}
Where:
- I've added the following line of the code to set the Event as "ACTIVE" event by default.
// ADDING EVENT STATUS BY DEFAULT
update_post_meta($post_id,'wpcf-event-status','ACTIVE');
I see you set the by default status from custom fields settings to "ACTIVE" But that does not mean that the event status will be automatically added. That is way we are setting the event status as you can see above using update_post_meta() function.
Can you please confirm now it works as expected now.